Bug: redbean: iterating unix.opendir can lead to random crashes with SIGSEGV SIGV_ACCERR #1337
Labels
medium severity
Used to report medium severity bugs (e.g. Malfunctioning Features but still useable)
Contact Details
No response
What happened?
Some time ago, I started getting random crashes with SIGSERV SIGV_ACCERR error. At first they weren't happening often, but then as I started doing more and more file system operations, they became very common (and very annoying 😅).
Crashes were occuring quite randomly, at different places, once I even had a crash that happened while server was idle.
One thing was common: the stack trace would always end with
LuaUnixDirClose
andclosedir
.When dealing with file system, my typical approach is to crawl a directory recursively with
for name, kind in assert(unix.opendir(dir or '.')) do ... end
, collecting a list of files into a table, and then do some operations with those files. For example, copy a bunch of files somewhere, concatenate them into one file, etc.Running with
--strace
showed that the crash was happening during garbage collection. A bunch of file descriptors were closed, last of them failing:(
munmap
calls skipped for brevity, full log attached below)After tracking file descriptors, I found that there were 2 descriptors pointing to the same folder:
Interestingly, those two
openat
calls belong to different requests and different API endpoints.I think this was what caused crashes - trying to close same fd twice.
I changed my code to explicitly close the
Dir
, and crashes stopped.Version
redbean 3.0.0, also tried with a version from cosmo.zip from 12-Dec-2024
What operating system are you seeing the problem on?
Windows
Relevant log output
Full log doesn't fit, I had to attach it as a file: strace2_full.txt
The text was updated successfully, but these errors were encountered: