WeBWorK Main Forum

Can't use undefined value as an ARRAY reference in Utils.pm

Can't use undefined value as an ARRAY reference in Utils.pm

by Jeremy Sylvestre -
Number of replies: 3
Some of my students have been getting the following error recently:

Can't use an undefined value as an ARRAY reference at /opt/webwork/webwork2/lib/WeBWorK/Utils.pm line 867.

This is on WW version 2.9. The server has been running fine since the start of the term, but this error occurred once last week and three more times in the last couple of days. It doesn't seem to be tied to any particular student or problem --- each of the four occurrences were a different student and a different problem. It seems to be a problem with writing and then re-reading the student's answer to/from the database.

I've attached a plain text file with two database queries related to the first occurrence of the problem. You can see that AnSwEr0005 has been properly recorded in the _past_answers table but not in the _problem_user table.

Any ideas on preventing this error from popping up again? The only thing I can think of is that perhaps /tmp or /run were hovering around full. (I forgot to check before rebooting the server this morning.) Does the database server need to write to one of these directories when updating? I'm using MariaDB. Though looking through journalctl output for the last couple of days, I don't see any "out of space" type messages.

Thanks in advance!
In reply to Jeremy Sylvestre

Re: Can't use undefined value as an ARRAY reference in Utils.pm

by Jeremy Sylvestre -
This error is rearing its head again. This time I can reproduce it reliably on the following two problems from the OPL:

Library/TCNJ/TCNJ_MatrixInverse/problem14.pg
Library/TCNJ/TCNJ_MatrixInverse/problem15.pg

It seems to occur when the answer to be parsed/recorded is very long. For example, in TCNJ_MatrixInverse/problem14.pg there are 8 2x2 matrix answer arrays and 8 3x3 matrix answer arrays, so that's 104 answer boxes altogether.

As another test, I tried entering a very long answer (494 characters, in fact) into

Library/WHFreeman/Rogawski_Calculus_Early_Transcendentals_Second_Edition/3_Differentiation/3.2_The_Derivative_as_a_Function/3.2.25.pg

and the same thing happened. Field last_answer in table COURSE_problem_user is Type=text, so it should be able to handle 65535 bytes. I don't see any relevant mysqld error/warning messages in the system logs around the times that these errors occurred.

Is there some input length restriction setting somewhere I can change to avoid this happening?

Steps to reproduce problem:

1. Enter and submit a very long answer into a problem.
2. After WeBWorK returns correct/incorrect status for the submitted answer, reload the problem (e.g. click on the problem # link in the menus on the left). WeBWorK will return an error page with error message

Can't use an undefined value as an ARRAY reference at /opt/webwork/webwork2/lib/WeBWorK/Utils.pm line 867.

Any advice on how to debug this problem would be appreciated...
Jeremy Sylvestre
In reply to Jeremy Sylvestre

Re: Can't use undefined value as an ARRAY reference in Utils.pm

by Jeremy Sylvestre -
OK, I believe I figured it out (sort of). It seems to be because the default CHARACTER SET for text fields in my database is utf8. In particular, this seems to cause a problem for the last_answer field in the _problem_user tables.

The Storable::nfreeze command in WeBWorK::Utils::encodeAnswers prefixes each field with a byte or two indicating the length of the data in the field. When the answer entered is <= 127 characters, this data length byte is in the ordinary ascii range and there's no problem. But as soon as the answer data > 127 characters, it spills over into the unicode range. For some reason the database doesn't like this at all, and truncates the last_answer data at the first occurrence of such a character.

On a test WW server, after issuing the following command the problem does not occur for the modified course.

MariaDB [webwork]> ALTER TABLE Testing_problem_user MODIFY last_answer TEXT CHARACTER SET 'binary' COLLATE 'binary';

I think that one should consider the serialized answer data obtained from the Storable::nfreeze command as binary data rather than text. Maybe WeBWorK::DB::Record::UserProblem should be changed so that last_answer has type BLOB instead of TEXT ?

In reply to Jeremy Sylvestre

Re: Can't use undefined value as an ARRAY reference in Utils.pm

by Jeremy Sylvestre -
And on a related note, maybe WeBWorK::Utils::decodeAnswers needs some error checking to catch corrupt last_answer entries in the database? Does Storable::thaw not have a mechanism for indicating whether it read in what it expected to read in?