cesanta / mongoose-wizard

2 stars 1 forks source link

Occasional write errors on file uploads #28

Open cpq opened 5 days ago

cpq commented 5 days ago

File uploads are not completing successfully. When a file is uploaded, the browser spins forever waiting for the upload to complete.

On the mongoose_glue side, the file open callback is called successfully and returns a valid pointer, and the file write callback is sometimes called and some data is written. The file close callback is never called. Looking more closely, the first few bytes of the file didn't get supplied or written.

Going deeper, into mongoose_impl.c prep_upload() the c->recv buffer contains the headers and the missing part of the file. After mg_iobuf_del is called on c->recv, c->recv contains just the missing part of the file (as expected).

When (if) mongoose_impl.c upload_handler() is called after this, the contents of c->recv are missing the first part of the file, and contain the next chunk or remainder of the file.

Somewhere between exiting prep_upload() and entering upload_handler() (with the next block of data, if any) the contents of c->recv are getting destroyed, I haven't yet figured out where.

Occasionally the file will upload completely normally, but mostly it won't. I haven't figured out what is changing between a successful upload and a faulty one. Sometimes it seems like theres a connection between the relative size of the file and the MG_IO_SIZE, but it's not consistent that I can tell.

I'm running on ESP32, with several web services running (MQTT client with JSON-RPC, HTTP server, and a diy NTP server).

I've traced it about as far as I can, would appreciate your input. I'm about to try various older versions of mongoose.c to try and find a regression...

cpq commented 4 days ago

@dvosully that's fixed, please verify