Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hello world Mummy web server crashes on devel #23724

Closed
hamidb80 opened this issue Jun 15, 2024 · 17 comments
Closed

hello world Mummy web server crashes on devel #23724

hamidb80 opened this issue Jun 15, 2024 · 17 comments

Comments

@hamidb80
Copy link
Contributor

hamidb80 commented Jun 15, 2024

Description

the following code is a hello world web server using mummy which crashes when you hit send multiple times in Insomnia ( an app similar to Postman, for testing API's )

import std/os
import mummy, mummy/routers


proc index(req: Request) =
  sleep 300
  req.respond 200, emptyHttpHeaders(), "Hello, World!"

proc initRouter: Router = 
  result.get "/", index

let server = newServer initRouter()

when isMainModule:
  echo "Serving on http://localhost:6001/"
  serve server, Port 6001, "localhost"

Nim Version

Nim Compiler Version 2.1.1 [Windows: amd64]
Compiled at 2024-06-10
Copyright (c) 2006-2024 by Andreas Rumpf

active boot switches: -d:release

Current Output

Serving on http://localhost:6001/

Traceback (most recent call last)
\play.nim(16) play
\.nimble\pkgs2\mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6\mummy.nim(1441) serve
\.nimble\pkgs2\mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6\mummy.nim(1345) loopForever
\.nimble\pkgs2\mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6\mummy.nim(1067) afterRecv
\.choosenim\toolchains\nim-#devel\lib\std\envvars.nim(217) afterRecvHttp
SIGSEGV: Illegal storage access. (Attempt to read from nil?)

Expected Output

no crash

Possible Solution

no idea

Additional Information

tested in Windows 10.

  • does not crash until 2.0.4
  • crashes in devel
@hamidb80 hamidb80 changed the title simple mummy web server crashes on devel hello world mummy web server crashes on devel Jun 15, 2024
@hamidb80 hamidb80 changed the title hello world mummy web server crashes on devel hello world Mummy web server crashes on devel Jun 15, 2024
@Araq
Copy link
Member

Araq commented Jun 16, 2024

Works for me. Does it start to work with -d:useMalloc for you?

@hamidb80
Copy link
Contributor Author

Does it start to work with -d:useMalloc for you?

Yes, no problem with -d:useMalloc

@Araq
Copy link
Member

Araq commented Jun 26, 2024

Should be fixed by #23758

If not, please reopen.

@Araq Araq closed this as completed Jun 26, 2024
@hamidb80
Copy link
Contributor Author

nope, same

nim r -f .\play.nim

output

CC: play.nim
Hint:  [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
68866 lines; 12.628s; 114.539MiB peakmem; proj: C:\Users\HamidB80\Documents\programming\Enterprise_Computing\play.nim; out: C:\Users\HamidB80\nimcache\play_d\play_91241B8910B9117BF80A2135A8BC4658211A04CC.exe [SuccessX]
Hint: C:\Users\HamidB80\nimcache\play_d\play_91241B8910B9117BF80A2135A8BC4658211A04CC.exe [Exec]
Serving on http://localhost:6001/
Traceback (most recent call last)
C:\Users\HamidB80\Documents\programming\Enterprise_Computing\play.nim(16) play
C:\Users\HamidB80\.nimble\pkgs2\mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6\mummy.nim(1441) serve
C:\Users\HamidB80\.nimble\pkgs2\mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6\mummy.nim(1345) loopForever
C:\Users\HamidB80\.nimble\pkgs2\mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6\mummy.nim(1067) afterRecv
C:\Users\HamidB80\.choosenim\toolchains\nim-#devel\lib\std\envvars.nim(217) afterRecvHttp
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Error: execution of an external program failed: 'C:\Users\HamidB80\nimcache\play_d\play_91241B8910B9117BF80A2135A8BC4658211A04CC.exe'      

Nim Version

PS C:\Users\HamidB80\Documents\programming\Enterprise_Computing> nim -v
Nim Compiler Version 2.1.1 [Windows: amd64]
Compiled at 2024-06-26
Copyright (c) 2006-2024 by Andreas Rumpf

active boot switches: -d:release
PS C:\Users\HamidB80\Documents\programming\Enterprise_Computing> 

@hamidb80
Copy link
Contributor Author

If not, please reopen.

seems like I cannot reopen this issue, due to changes in Github
image

@Araq Araq reopened this Jun 26, 2024
@Araq
Copy link
Member

Araq commented Jun 26, 2024

Is this problem reproducible on Linux?

@hamidb80
Copy link
Contributor Author

hamidb80 commented Jun 26, 2024

Is this problem reproducible on Linux?

unfortunately yes,

CC: play.nim
Hint:  [Link]
Hint: mm: orc; threads: on; opt: none (DEBUG BUILD, `-d:release` generates faster code)
69976 lines; 6.888s; 114.988MiB peakmem; proj: /home/hamidb80/Documents/programming/play/play.nim; out: /home/hamidb80/.cache/nim/play_d/play_A868D214FBFE7FA0D1C492875840D762FD8CA67C [SuccessX]
Hint: /home/hamidb80/.cache/nim/play_d/play_A868D214FBFE7FA0D1C492875840D762FD8CA67C 

[Exec]
Serving on http://localhost:6001/

Traceback (most recent call last)
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(518) workerProc
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(449) runTask
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy/routers.nim(221) :anonymous
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)
Error: execution of an external program failed: '/home/hamidb80/.cache/nim/play_d/play_A868D214FBFE7FA0D1C492875840D762FD8CA67C'
$ nim -v
Nim Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-06-26
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 948fc29bb20018437678e7c11019f1f2455c3a72
active boot switches: -d:release
$ lsb_release -a
Distributor ID:	Ubuntu
Description:	Ubuntu 20.04.1 LTS

@Araq
Copy link
Member

Araq commented Jun 26, 2024

No, that's great news! Makes it much easier to fix.

@Araq
Copy link
Member

Araq commented Jun 26, 2024

Cannot reproduce on Linux either. Even compiling with -d:useSysAssert is fine. Try it with -d:useSysAssert please.

@Araq
Copy link
Member

Araq commented Jun 26, 2024

I don't use Insomnia though, I simply use my browser and navigate to http://localhost:6001/.

@hamidb80
Copy link
Contributor Author

Hey, I truly appreciate your time and attention,

here's the modified code (I've made it single threaded by workerThreads = 1)

import std/os
import mummy, mummy/routers


proc index(req: Request) =
  sleep 300
  req.respond 200, emptyHttpHeaders(), "Hello, World!"

proc initRouter: Router = 
  result.get "/", index

let server = newServer(initRouter(), workerThreads = 1)

when isMainModule:
  echo "Serving on http://localhost:6001/"
  serve server, Port 6001, "localhost"

Result

1. Sometimes without -d:useSysAssert

$ nim -f r play.nim 

/home/hamidb80/Documents/programming/play/play.nim(16) play
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(1441) serve
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(1345) loopForever
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(1067) afterRecv
/home/hamidb80/.choosenim/toolchains/nim-#devel/lib/std/envvars.nim(217) afterRecvHttp
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)

2. Sometimes without -d:useSysAssert

$ nim -f r play.nim 

/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(1441) serve
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(1345) loopForever
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(1067) afterRecv
/home/hamidb80/.nimble/pkgs2/mummy-0.4.2-2c3d0bdf8525a27ff1eae97e9f23695022eabbb6/mummy.nim(908) afterRecvHttp
/home/hamidb80/.choosenim/toolchains/nim-#devel/lib/pure/strutils.nim(50) cmpIgnoreCase
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault (core dumped)

3.always with d:useSysAssert

$ nim -f -d:useSysAssert r play.nim 

[Exec]
Serving on http://localhost:6001/
Dropped response to disconnected client
[SYSASSERT] rawAlloc 3

Nim Version

$ nim -v 
im Compiler Version 2.1.1 [Linux: amd64]
Compiled at 2024-06-26
Copyright (c) 2006-2024 by Andreas Rumpf

git hash: 948fc29bb20018437678e7c11019f1f2455c3a72
active boot switches: -d:release

@hamidb80
Copy link
Contributor Author

I don't use Insomnia though, I simply use my browser and navigate to http://localhost:6001/.

no problem, just hit Ctrl+R multiple times

@Araq
Copy link
Member

Araq commented Jun 26, 2024

no problem, just hit Ctrl+R multiple times

That's what I do, but as I said, cannot reproduce. Probably I should use wrk and run a stress test.

@hamidb80
Copy link
Contributor Author

hamidb80 commented Jun 26, 2024

but as I said, cannot reproduce

strange, does my Nim's git hash matches yours?
948fc29bb20018437678e7c11019f1f2455c3a72

can anyone else give it a try?

@Araq
Copy link
Member

Araq commented Jun 26, 2024

You need:

commit 8096fa4
Date: Wed Jun 26 05:09:05 2024 +0200

fixes #23725; Size computations work better when they are correct (#23758)

[backport]

@hamidb80
Copy link
Contributor Author

I thought choosenim update devel downloaded latest Nim version

@hamidb80
Copy link
Contributor Author

hamidb80 commented Jun 26, 2024

I'm really sorry for that,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants