httpbeast icon indicating copy to clipboard operation
httpbeast copied to clipboard

Random segmentation fault when using orc and threads more than 1

Open dirtboll opened this issue 3 years ago • 5 comments

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. https://github.com/dom96/httpbeast/blob/7de559e6eab97763bae16b8a973373e9fe691574/src/httpbeast.nim#L336-L339

dirtboll avatar Oct 31 '22 06:10 dirtboll

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?

dom96 avatar Oct 31 '22 10:10 dom96

Sure, I'll post the issue there too.

dirtboll avatar Oct 31 '22 12:10 dirtboll

@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.

PMunch avatar Feb 22 '23 10:02 PMunch

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

dirtboll avatar Feb 22 '23 15:02 dirtboll

have you tried after https://github.com/dom96/httpbeast/pull/89 merged ? I run test locally result seem stable green.

bung87 avatar Aug 08 '23 01:08 bung87