parse-server icon indicating copy to clipboard operation
parse-server copied to clipboard

Timeout in FileAdapter or Empty response from server when trying to upload a small size file

Open cjosepha opened this issue 9 years ago • 10 comments

Issue Description

I try to save a 19MB file via the rest api with Curl. Sometimes Curl indicates that the server response is empty, and sometimes the server respond with code 130 "Could not store file." This behavior is totally unpredictable and seems due to a timeout error in the FileAdapter. I tried with both the S3Adapter and the default GridStoreAdapter and they produce the same behavior that I've just mentioned.

When response is {"code":130,"error":"Could not store file."} the server logs indicates a timeout in the FileAdapter:

  • connection 6 to ... timed out for the GridStoreAdapter
  • Connection timed out after 120000ms for the S3Adapter

I think this unpredictable behavior is a bug that should be fixed to save debugging time as the first responses was empty in my cases, so I didn't know there was a timeout issue. Also note that sometimes, the timeout error log on the server can appear after (a few minutes) the Curl command returns and indicates that response is empty.

Can anyone provide me some answers about this :

  • Should not the return code always be 124?
  • Is there a way to avoid the timeout for file saving operations? If not, should not one be provided?

Steps to reproduce

  • My internet connection upload speed is 0.3Mbps
  • File to upload is a text file of 19MB I created for test purpose
  • Curl command: curl -X POST
    -H "X-Parse-Application-Id: APP_ID"
    -H "X-Parse-Master-Key: MASTER_KEY"
    -H "Content-Type: text/plain"
    -d "@file.txt"
    http://localhost:1337/parse/files/file.txt

Expected Results

File successfully created as the file is under the 20MB limit.

Actual Outcome

Either an empty response or code 130 "Could not store file.", randomly.

Environment Setup

  • Server

    • parse-server version (Be specific! Don't say 'latest'.) : 2.3.7, 2.3.8, 2.4.0
    • Operating System: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, Heroku, Azure, Digital Ocean, etc): localhost
  • Database

    • MongoDB version: 3.0.10
    • Storage engine: [FILL THIS OUT]
    • Hardware: [FILL THIS OUT]
    • Localhost or remote server? (AWS, mLab, ObjectRocket, Digital Ocean, etc): AWS

Logs/Trace

With GridStoreAdapter: connection 6 to ... timed out MongoError: connection 6 to ... timed out at Function.MongoError.create (/Users/.../dist/node_modules/mongodb-core/lib/error.js:29:11) at Socket. (/Users/.../dist/node_modules/mongodb-core/lib/connection/connection.js:188:20) at Socket.g (events.js:291:16) at emitNone (events.js:86:13) at Socket.emit (events.js:185:7) at Socket._onTimeout (net.js:339:8) at ontimeout (timers.js:365:14) at tryOnTimeout (timers.js:237:5) at Timer.listOnTimeout (timers.js:207:5)

With S3Adapter: Connection timed out after 120000ms TimeoutError: Connection timed out after 120000ms at ClientRequest. (/Users/.../dist/node_modules/aws-sdk/lib/http/node.js:83:34) at ClientRequest.g (events.js:291:16) at emitNone (events.js:86:13) at ClientRequest.emit (events.js:185:7) at TLSSocket.emitTimeout (_http_client.js:626:10) at TLSSocket.g (events.js:291:16) at emitNone (events.js:86:13) at TLSSocket.emit (events.js:185:7) at TLSSocket.Socket._onTimeout (net.js:339:8) at ontimeout (timers.js:365:14)

cjosepha avatar May 18 '17 20:05 cjosepha

You need to set the maxUploadSize, it's 20Mb by default https://github.com/parse-community/parse-server/blob/master/src/ParseServer.js#L122

flovilmart avatar May 18 '17 21:05 flovilmart

@flovilmart So why can't I upload a 19MB file

cjosepha avatar May 18 '17 21:05 cjosepha

@flovilmart I just set the maxUploadSize to '30mb' and result is exactly the same.

cjosepha avatar May 18 '17 21:05 cjosepha

ANd if you bump it even more?

flovilmart avatar May 18 '17 21:05 flovilmart

@flovilmart Just set '100mb' and nothing changed

cjosepha avatar May 18 '17 21:05 cjosepha

I'll have a look

flovilmart avatar May 18 '17 22:05 flovilmart

Are you noticing the issue only locally? What are the logs when running with VERBOSE=1?

flovilmart avatar Jul 23 '17 15:07 flovilmart

I don't remember if this was the case at the time I created the issue. But now, with parse-server 2.6.3 on a remote server, there is no more timeout. This allowed me to go further and to discover I had to increase the http request body size in the server configuration. Now larger files can be uploaded.

cjosepha avatar Oct 27 '17 20:10 cjosepha

@cjosepha Hi can you pls share how you did this i'm also facing the same issue, i cannot upload large files

Sarun1001 avatar Jan 02 '23 16:01 Sarun1001

@Sarun1001 basically I upgraded to higher Parse version and also edited my nginx configuration to increase the request body maximum size

cjosepha avatar Jan 09 '23 10:01 cjosepha