Server fns of fullstack service used in combination with axum fail causing empty response from server
Problem
I tried to get fullstack to work with an axum backend, so naturally I tried running packages/fullstack/examples/axum-auth/ on main as it was working fine on v0.4.3, but it wasn't working at all. I believe the primary reason for it not working properly is caused by the API/server fns part of the server not being handled properly as seemingly all attempts to fetch these fail with Empty reply from server probably caused by a race of sorts or improper use of async as the server outputs:
thread 'tokio-runtime-worker' panicked at packages/fullstack/src/server_context.rs:95:24:
Cannot block the current thread from within a runtime. This happens because a function attempted to block the current thread while the thread is being used to drive asynchronous tasks.
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
for each of these.
Steps To Reproduce
Steps to reproduce the behavior:
-
cdinto dioxus repo - make sure you're on latest
main(b58a3bb) -
cdintoaxum-authexample (cd packages/fullstack/examples/axum-auth/) - start server (
cargo run --features serverordx serve --platform fullstack) - trigger one of the server fns:
curl -vvvv 'http://localhost:3000/api/login16614828771088123554' -X POST -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0' -H 'Accept: application/json' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:3000/' -H 'content-type: application/x-www-form-urlencoded' -H 'Content-Length: 0' -H 'Origin: http://localhost:3000' -H 'Connection: keep-alive' -H 'Cookie: session=b18d06fa-ea8d-4313-bf35-b0ffcb84a3f9' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin'
* Trying [::1]:3000...
* connect to ::1 port 3000 failed: Connection refused
* Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000
> POST /api/login16614828771088123554 HTTP/1.1
> Host: localhost:3000
> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0
> Accept: application/json
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate, br
> Referer: http://localhost:3000/
> content-type: application/x-www-form-urlencoded
> Content-Length: 0
> Origin: http://localhost:3000
> Connection: keep-alive
> Cookie: session=b18d06fa-ea8d-4313-bf35-b0ffcb84a3f9
> Sec-Fetch-Dest: empty
> Sec-Fetch-Mode: cors
> Sec-Fetch-Site: same-origin
>
* Empty reply from server
* Closing connection
curl: (52) Empty reply from server
Expected behavior
The expected behavior is as it was in v0.4.3, i.e. server fns seem to respond fine. Unfortunately the version of axum_session_auth used (0.3.0) has been yanked but if you need to see it as it was then I pushed a workaround that depends on the corresponding rev here: https://github.com/s1gtrap/dioxus/tree/workaround-yanked-auth
If you clone the above and follow the steps to reproduce (except with cargo run --features ssr instead of --features server) it works as expected (i.e. POST request correctly sets the session cookie):
curl -vvvv 'http://localhost:3000/api/login16614828771088123554' -X POST -H 'User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0' -H 'Accept: application/json' -H 'Accept-Language: en-US,en;q=0.5' -H 'Accept-Encoding: gzip, deflate, br' -H 'Referer: http://localhost:3000/' -H 'content-type: application/x-www-form-urlencoded' -H 'Content-Length: 0' -H 'Origin: http://localhost:3000' -H 'Connection: keep-alive' -H 'Cookie: session=b18d06fa-ea8d-4313-bf35-b0ffcb84a3f9' -H 'Sec-Fetch-Dest: empty' -H 'Sec-Fetch-Mode: cors' -H 'Sec-Fetch-Site: same-origin'
* Trying [::1]:3000...
* connect to ::1 port 3000 failed: Connection refused
* Trying 127.0.0.1:3000...
* Connected to localhost (127.0.0.1) port 3000
> POST /api/login16614828771088123554 HTTP/1.1
> Host: localhost:3000
> User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:123.0) Gecko/20100101 Firefox/123.0
> Accept: application/json
> Accept-Language: en-US,en;q=0.5
> Accept-Encoding: gzip, deflate, br
> Referer: http://localhost:3000/
> content-type: application/x-www-form-urlencoded
> Content-Length: 0
> Origin: http://localhost:3000
> Connection: keep-alive
> Cookie: session=b18d06fa-ea8d-4313-bf35-b0ffcb84a3f9
> Sec-Fetch-Dest: empty
> Sec-Fetch-Mode: cors
> Sec-Fetch-Site: same-origin
>
< HTTP/1.1 405 Method Not Allowed
< allow: GET,HEAD
< set-cookie: session_key=; HttpOnly; Path=/; Max-Age=0; Expires=Wed, 01 Mar 2023 11:19:37 GMT
< set-cookie: sqlx_session=9f426a5e-5330-403e-94d6-3df1ab91f644; HttpOnly; SameSite=Lax; Path=/; Expires=Sat, 08 Jun 2024 11:19:37 GMT
< set-cookie: session_acceptance=false; HttpOnly; SameSite=Lax; Path=/; Expires=Sat, 08 Jun 2024 11:19:37 GMT
< content-length: 0
< date: Thu, 29 Feb 2024 11:19:37 GMT
<
* Connection #0 to host localhost left intact
Screenshots
If applicable, add screenshots to help explain your problem.
Environment:
- Dioxus version:
main - Rust version:
nightly - OS info: MacOS
- App platform:
fullstack
Questionnaire
- [ ] I'm interested in fixing this myself but don't know where to start
- [ ] I would like to fix and I have a solution
- [ ] I don't have time to fix this right now, but maybe later