Multiple uploads result in Cowboy exit

We have an upload form in our application that allows for multiple / simultaneous uploads by the user.
When the user drops file by file, everything works as expected. However, if he drops multiple files at once, some of them are uploaded successfully, others result in a Cowboy related error for each failed file upload.

Ranch listener AppWeb.Endpoint.HTTP had connection process started with :cowboy_clear:start_link/4 at #PID<0.4182.0> exit with reason: {:function_clause, [{ ....

Full error: https://gist.github.com/pierot/3a7fc1c6ecbae3c3ba82cb2b30c35251

I cannot reproduce this locally, at least not with the same error. Locally I sometimes get:

Ranch listener JustifiedWeb.Endpoint.HTTPS had connection process started with :cowboy_tls:start_link/4 at #PID<0.3052.0> exit with reason: {{:badmatch, :undefined},

On production we run the application in HTTP (not HTTPS) behind Cloudflare -> Traefik. Maybe this is related to the error somehow.

We have been searching for the cause, without any luck.

Also (working on the same app :smiley: ) it would be interesting to know how we would go about handling/catching this error?

Update on our side: we seemed to have fixed it… After some testing on my local machine I noticed a myxql related error, connection that went away.

It seemed that when dropping a lot of small files simultaneously the client side plugin (dropzone.js) was very eager to send all of those requests to the server – which was fine – but that resulted in a lot of simultaneous calls to the database, at almost exactly the same time.

We hit the db because we need a related resource in order to know where to put the file. Instead of doing it per request, we now fetch that resource once up front and then per file we just pass in the fetched resource, resulting in 1 query altogether instead of n-queries (n = amount of files).

But, we remain interested how the initial error we had relates to this error, and how there was no trace of the db call failing in the ‘process tree’ or what not. I just spotted it by accident on my local machine. Would love to learn how we should have gone about tackling this.

1 Like