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

SIGSEGV from OpenSSL when used in async context #24024

Open
PMunch opened this issue Aug 28, 2024 · 0 comments
Open

SIGSEGV from OpenSSL when used in async context #24024

PMunch opened this issue Aug 28, 2024 · 0 comments

Comments

@PMunch
Copy link
Contributor

PMunch commented Aug 28, 2024

Description

While performing many queries in a row to our API the code at some point errors out with a SIGSEGV. This comes from ssl3_read_bytes which in turn is called from https://github.com/nim-lang/Nim/blob/version-2-0/lib/pure/asyncnet.nim#L328. Starting each AsyncHttpClient with their own SSLContext seems to have helped somewhat, but the error still occurs occasionally. My best guess is that there is some condition where SSL needs some extra care that AsyncHttpClient doesn't provide, and this corrupts the SSLContext leading to the SIGSEGV. But that is just speculation based on the fact that this only happens sometimes.

Nim Version

Tested with 2.0.8

Current Output

This is a backtrace from GDB when the crash happens, line 112 in mycode.nim (redacted name and SSL buffer contents) is a call to waitFor on multiple connections combined with all.

#0  0x00007ffff7c39e4a in ssl3_read_bytes (ssl=<optimized out>, type=23 '\027', recvd_type=0x0, 
    buf=0x7ffff7ba3046 "<data>"..., len=4000, peek=0, readbytes=0x7fffffffd030) at ssl/record/rec_layer_s3.c:687
#1  0x00007ffff7be6989 in ssl3_read_internal (s=0x5555560006f0, buf=0x7ffff7ba3046, len=4000, peek=0, 
    readbytes=0x7fffffffd030) at ssl/s3_lib.c:4527
#2  0x00007ffff7bee56b in SSL_read (s=<optimized out>, buf=<optimized out>, num=<optimized out>) at ssl/ssl_lib.c:2328
#3  0x00005555555cdc96 in _ZN4recv19recvX20X28AsyncX29_E (ClE_0=0x7fffeab86280)
    at /home/peter/.choosenim/toolchains/nim-2.0.8/lib/pure/asyncnet.nim:328
#4  0x00005555555c92f7 in _ZN4recv20recvNimAsyncContinueE (ClE_0=0x7ffff7b824c0)
    at /home/peter/.choosenim/toolchains/nim-2.0.8/lib/pure/asyncmacro.nim:33
#5  0x00005555555bc2b7 in _ZN13asyncdispatch23processPendingCallbacksE3refIN13asyncdispatch31PDispatcherBasecolonObjectType_EE3varI4boolE (p_p0=p_p0@entry=0x7ffff7b54120, didSomeWork_p1=didSomeWork_p1@entry=0x7fffffffd1bf)
    at /home/peter/.choosenim/toolchains/nim-2.0.8/lib/pure/asyncdispatch.nim:269
#6  0x00005555555bc5ac in _ZN13asyncdispatch7runOnceE3int (timeout_p0=timeout_p0@entry=500)
    at /home/peter/.choosenim/toolchains/nim-2.0.8/lib/pure/asyncdispatch.nim:1452
#7  0x00005555555bc94a in _ZN13asyncdispatch4pollE3int (timeout_p0=timeout_p0@entry=500)
    at /home/peter/.choosenim/toolchains/nim-2.0.8/lib/pure/asyncdispatch.nim:1711
#8  0x00005555555bfd9f in _ZN13asyncdispatch7waitForE6FutureI4voidE (fut_p0=fut_p0@entry=0x7ffff7b5a760)
    at /home/peter/.choosenim/toolchains/nim-2.0.8/lib/pure/asyncdispatch.nim:2022
#9  0x0000555555603287 in NimMainModule () at mycode.nim:112
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

No branches or pull requests

1 participant