kit icon indicating copy to clipboard operation
kit copied to clipboard

Form action stalls while awaiting formData for certain requests

Open moatra opened this issue 1 year ago • 6 comments

Describe the bug

I managed to capture a formData post request that causes an action handler's event.request.formData() promise to never resolve. This appears to be platform dependent, as it does not reproduce when running on my MacBook.

Reproduction

  1. Clone https://github.com/moatra/sveltekit_formdatahang
  2. npm install
  3. npm run dev

In another terminal:

  1. Inspect the contents of repro.sh (it's a curl request that posts to http://localhost:5173/post/form with the headers and body that seem to reproduce this problem)
  2. Execute ./repro.sh Bug: The request hangs, never generating a reply (neither success nor error)

Comparison:

  1. Change the destination of the curl request to http://localhost:5173/post/text
  2. Execute ./repro.sh Working as intended: the event.request.text() promise resolves with the body of the request.

Logs

None on the sveltekit side, unfortunately.  As best as I can tell, the byte stream of the request body is not being properly consumed.

Verbose curl logs:
Note: Unnecessary use of -X or --request, POST is already inferred.
*   Trying 127.0.0.1:5173...
* Connected to localhost (127.0.0.1) port 5173 (#0)
> POST /post/form HTTP/1.1
> Host: localhost:5173
> User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/119.0
> Accept: application/json
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate, br
> Referer: http://localhost:5173/
> Content-Type: multipart/form-data; boundary=---------------------------10208687901308681982731915031
> Origin: http://localhost:5173
> Connection: keep-alive
> Cookie: login_token_v1=redacted; unsecured_session=%7B%22current_tz%22%3A%22America%2FChicago%22%2C%22partner_id%22%3A%2201H5JN838SKVEG12MK745RYJR2%22%2C%22fleet_id%22%3A%2201HFV2850RXBAC3D1KQ7H65BRW%22%2C%22boat_id%22%3A%2201HFV28FA6CMW3BEF3KTDHVYJF%22%7D
> Sec-Fetch-Dest: empty
> Sec-Fetch-Mode: cors
> Sec-Fetch-Site: same-origin
> Content-Length: 17332
> 
(hangs here)

System Info

sveltekit_formdatahang on  master [!] via  v18.7.0 took 2s 
❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: Linux 6.5 Pop!_OS 22.04 LTS
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 45.77 GB / 62.68 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.7.0 - /usr/local/bin/node
    npm: 8.15.0 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
    @sveltejs/kit: ^1.27.4 => 1.27.6 
    svelte: ^4.2.7 => 4.2.7 
    vite: ^4.4.2 => 4.5.0

Severity

serious, but I can work around it

Additional Information

No response

moatra avatar Nov 26 '23 06:11 moatra

System info from my mac, which can't reproduce the hang:

formpost_hang on  master via  v21.2.0 took 2s 
❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: macOS 12.7.1
    CPU: (8) x64 Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz
    Memory: 99.90 MB / 16.00 GB
    Shell: 5.8.1 - /bin/zsh
  Binaries:
    Node: 21.2.0 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
  Browsers:
    Chrome: 119.0.6045.159
    Safari: 17.1
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
    @sveltejs/kit: ^1.27.4 => 1.27.6 
    svelte: ^4.2.7 => 4.2.7 
    vite: ^4.4.2 => 4.5.0

moatra avatar Nov 26 '23 06:11 moatra

Results from updating the node version on my linux machine:

sveltekit_formdatahang on  master [!] via  v18.18.2 took 15s 
❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: Linux 6.5 Pop!_OS 22.04 LTS
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 45.74 GB / 62.68 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 18.18.2 - /usr/local/bin/node
    npm: 9.8.1 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
    @sveltejs/kit: ^1.27.4 => 1.27.6 
    svelte: ^4.2.7 => 4.2.7 
    vite: ^4.4.2 => 4.5.0 

Result: still hangs

sveltekit_formdatahang on  master [!] via  v20.10.0 
❯ npx envinfo --system --binaries --browsers --npmPackages "{svelte,@sveltejs/*,vite}"

  System:
    OS: Linux 6.5 Pop!_OS 22.04 LTS
    CPU: (16) x64 AMD Ryzen 7 3700X 8-Core Processor
    Memory: 45.61 GB / 62.68 GB
    Container: Yes
    Shell: 5.1.16 - /bin/bash
  Binaries:
    Node: 20.10.0 - /usr/local/bin/node
    npm: 10.2.3 - /usr/local/bin/npm
  npmPackages:
    @sveltejs/adapter-auto: ^2.0.0 => 2.1.1 
    @sveltejs/kit: ^1.27.4 => 1.27.6 
    svelte: ^4.2.7 => 4.2.7 
    vite: ^4.4.2 => 4.5.0 

Result: Success!


What's the current min-supported node version for svelte-kit?

moatra avatar Nov 26 '23 06:11 moatra

had the same problem. updating node from 20.9 to 20.10 fixed it for me.

chriswep avatar Jan 09 '24 16:01 chriswep

Had the same problem, upgrading to node 20.11 solved. THANK YOU!! I think is somehow related to SvelteKit v2 or maybe to https://github.com/sveltejs/kit/pull/11589 because I had no problems with SvelteKit v1

ftognetto avatar Feb 06 '24 15:02 ftognetto

Same issue here on linux. In a standard form with only text inputs (some hidden) , event.request.formData() never resolves. Upgraded from node 18.19 to 20.11 and the problem's resolved. I only figured it out when I couldn't manage to create a reproduction and noticed stackblitz was running 18.18 which also works.

rumack avatar Feb 11 '24 00:02 rumack

Seems to be related to the number of hidden inputs in my case. Also, the formdata request doesn't hang if I don't use enhance. I created a repro here: https://github.com/rumack/form-action-bug but you'll need to use node 18.19 on a linux machine to see the issue. Node version 18.18 works fine, as does 20.11. And I don't have the issue when running the repro on a macbook, only my linux machine.

[Edit] Seems the 'content-length' header of the form is limited to 16kb (about 16385). Setting the BODY_SIZE_LIMIT env var to Infinity or any other value doesn't fix it. And anyway, the BODY_SIZE_LIMIT default is supposed to be 512kb .

rumack avatar Feb 11 '24 14:02 rumack

WOW this is so interesting.

I remember first running into this problem on October 21, 2023; however, the latest NodeJS version was only 18.18.2 back then, which makes me wonder if 18.18.1 and 18.18.2 are borked as well. I know it was fine when I tried around September, so it makes sense it's a NodeJS version thing (I deployed on Vercel and had set it to use the latest 18.x version).

Luckily changing it to 20.x fixed the issue, but I'm still really curious as to what could cause this...

FWIW, I'm able to consistently trigger the hang when I send enough data for a Content-Length of 16384 or greater. 16383 and less work. 16384 is exactly 16 KiB. Wonder what could be the significance of this.

@rumack I think it's just related to the size of the form data. I was able to reproduce in a form with zero hidden inputs, just sending Content-Length >= 16384.

danielzting avatar Mar 04 '24 18:03 danielzting

FWIW, I'm able to consistently trigger the hang when I send enough data for a Content-Length of 16384 or greater. 16383 and less work. 16384 is exactly 16 KiB. Wonder what could be the significance of this.

I can confirm this, which only occurs in Node versions 18.18.2 through 20.9.0 when using the :enhance. I've created another repro here that might be helpful.

mustofa-id avatar Mar 15 '24 03:03 mustofa-id

I was also experiencing this exact behavior on node v18.9.0 where submitting a form with a body of greater than ~16kb would just hang. Upgrading node to v20.13.1 solved the problem.

andyrue avatar May 21 '24 15:05 andyrue

Had this issue running SvelteKit on App Engine (where adapter-appengine completely reasonably defaults to Node 18). Bumping to 20 (ie, 20.latest) solves the issue.

I should note that we weren't using use:enhance; we were, however, using fetch from the client, which is where the issue lies, I believe.

infovore avatar Jun 04 '24 14:06 infovore