moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Michael Ko -
Počet odpovedí: 6

Hello.

Unfortunately we have been getting the following error many times:

FastCGI-stderr: PHP message: Potential coding error - active database transaction detected during request shutdown:
* line 52 of /mod/quiz/processattempt.php: call to moodle_database->start_delegated_transaction()

We are running Moodle version 2.6.2 (Build: 20140310) with PostgreSQL.

This error has caused the database's memory usage to increase dramatically.

I have had a look at this topic https://moodle.org/mod/forum/discuss.php?d=229365 and we have split the quizzes into multiple pages and our session timeout is 4 hours. I also read that this error could be caused by require_login() being called after moodle_database->start_delegated_transaction() (and having looked at the code, require_login is called about 40 lines later), however we have not changed the code because we are unsure if it is the solution and we currently have hundreds of students using the system.

Please help, any advice is appreciated.

Thank you.

Priemer hodnotení : -
V odpovedi na Michael Ko

Re: moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Michael Ko -

Should we move require_login() so it is executed before the transaction begins?

V odpovedi na Michael Ko

Re: moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Tim Hunt -
Obrázok: Core developers Obrázok: Documentation writers Obrázok: Particularly helpful Moodlers Obrázok: Peer reviewers Obrázok: Plugin developers

This error is a symptom, not a cause.

The real problem is that users are losign their login session in the middle of attempting a quiz (and hence losing their work).

This is a serious problem, and you need to investiate it. The fact they are using the quiz at the time is not relevant. You need to look at how your session handling and authentication is set up.

V odpovedi na Tim Hunt

Re: moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Michael Ko -

Hi Tim,

Thanks a lot for the response.

I have found some of the quiz attempts that experienced these problems and noticed that many of them were started several days before being completed.

So if someone starts a quiz, minimises it, comes back 4 days later and presses "Save and Submit" (or continues to the next page of the quiz), then isn't the system supposed to redirect them to the login page? In the config our timeout is 4 hours and it says: If people logged in to this site are idle for a long time (without loading pages) then they are automatically logged out (their session is ended). This variable specifies how long this time should be

I don't understand what the problem is with the database transaction. It appears that our session handling is working correctly. 

All of the answers entered into the quizzes are being saved anyway. I'm not sure if this is being done by processattempt or by the autosave ajax (which just now we have decided to disable).


Also, I have been trying to trace the occurrences in the logs and it appears that the mod/quiz/autosave.ajax.php logs contain OPTIONS instead of GET or POST (like all of the other autosave requests). I don't know if this is relevant though, and we have now disabled the autosave feature to reduce load on the server at this busy time.

[08/Jul/2014:11:49:05 +1000] "OPTIONS /mod/quiz/autosave.ajax.php HTTP/1.1"

V odpovedi na Michael Ko

Re: moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Tim Hunt -
Obrázok: Core developers Obrázok: Documentation writers Obrázok: Particularly helpful Moodlers Obrázok: Peer reviewers Obrázok: Plugin developers

It is perfectly OK for a quiz attempt to take 4 days. For example this sequence is fine, and will not cause any errors in the logs.

  1. Start quiz attempt.
  2. Answer some questions.
  3. Close your browser.
  4. Go away for the weekend.
  5. Log back into Moodle.
  6. Continue the attempt.
  7. Submit it.

The problem only happens if you miss out steps 3. and 5. and leave the browser tab open, and come back more than 4 hours later and try to continue.

In this case, the student is redirected to the login page, and that does lead to the error you see in the logs. Yes, it is technically a bug, but it is only a warning 'PHP-message', and causes no harm other than the noise in the logs.

Hence it is not a priority to fix it. There is a reason why I don't just want to move the start transaction lower in the file - I think to do with the normal case where the user's session has not expired. Getting that right is more important than a rare error in the logs. but you are right, it is a bug.


As for the OPTIONS thing, I had to Google that. This answer seems to explain. http://stackoverflow.com/questions/1099787/jquery-ajax-post-sending-options-as-request-method-in-firefox That applies ot Moodle as well as jQuery.

V odpovedi na Tim Hunt

Re: moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Michael Ko -

Thanks again for your response.

Unfortunately we have a serious memory leak which is threatening to crash our server, and this is the only error message appearing in our logs. It seems to be happening every 5-10 minutes.

From what I have found so far:

We have the following settings: $CFG->forcelogin = 'yes' and $CFG->alternateloginurl is set to an external webpage.

When it finds that the user is not logged in, it uses a 303 redirect to that login page. I understand that this causes the error "active database transaction detected during request shutdown" in the logs, but does this actually shut down the database transaction, or is it just left running?

V odpovedi na Michael Ko

Re: moodle_database->start_delegated_transaction() active database transaction detected during request shutdown

autor Tim Hunt -
Obrázok: Core developers Obrázok: Documentation writers Obrázok: Particularly helpful Moodlers Obrázok: Peer reviewers Obrázok: Plugin developers

Yes. Moodle automatically rolls back the transaction in that case, and then outputs the warning to tell you that you should not rely on the automatic roll-back.