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

Random segmentation fault when using orc and threads more than 1 #80

Open
dirtboll opened this issue Oct 31, 2022 · 5 comments
Open

Random segmentation fault when using orc and threads more than 1 #80

dirtboll opened this issue Oct 31, 2022 · 5 comments

Comments

@dirtboll
Copy link

This minimal code should reproduce the issue.

# hello.nim
import options, asyncdispatch, logging

import httpbeast

proc onRequest(req: Request): Future[void] =
  if req.httpMethod == some(HttpGet):
    case req.path.get()
    of "/":
      req.send("Hello World")
    else:
      req.send(Http404)

if logging.getHandlers().len == 0:
  addHandler(logging.newConsoleLogger())
  setLogFilter(when defined(release): lvlInfo else: lvlDebug)

run(onRequest, httpbeast.initSettings(numThreads=2))
nim c -r --gc:orc -d:releae --threads:on hello.nim
  • Nim version 1.6.8
  • httpbeast version 0.4.1
  • Run inside docker image nimlang/nim (also tried with WSL2 and GCP debian instance)

When running and killing the binary multiple times, the program sometimes runs but most of the times it gives this error:

root@4dfa057c787d:~# ./hello
Starting 2 threads
Listening on port 8080
Traceback (most recent call last)
/root/.nimble/pkgs/httpbeast-0.4.1/httpbeast.nim(83) eventLoop
/nim/lib/system/orc.nim(46) nimIncRefCyclic
SIGSEGV: Illegal storage access. (Attempt to read from nil?)
Segmentation fault

I initially found the issue when using Jester. After some searching I found that I can solve the issue by commenting this block of code. Other workaround that I did was modifying Settings.loggers to ref seq[Logger], which also removes the random segfault.

httpbeast/src/httpbeast.nim

Lines 336 to 339 in 7de559e

if not isMainThread:
# We are on a new thread. Re-add the loggers from the main thread.
for logger in settings.loggers:
addHandler(logger)

@dom96
Copy link
Owner

dom96 commented Oct 31, 2022

I expect ORC to be compatible with the current default GC so it would be nice to confirm whether this is an ORC bug. Can you raise the same in the Nim repo?

@dirtboll
Copy link
Author

Sure, I'll post the issue there too.

@PMunch
Copy link

PMunch commented Feb 22, 2023

@dirtboll, did you ever post in in the main repo? Would be nice to have the issue linked here so it's easier to track. I just faced the same issue today with the devel version of Nim which enables --gc:orc --threads:on by default.

@dirtboll
Copy link
Author

I forgot, it's been 4 months...
Yeah I've just tested it with the latest nightlies, still got it. Will post right away.

@bung87
Copy link
Contributor

bung87 commented Aug 8, 2023

have you tried after #89 merged ? I run test locally result seem stable green.

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

Successfully merging a pull request may close this issue.

4 participants