Skip to content

Occasional kqueue related crash on OpenBSD. #6596

Closed

Description

@vext01

Hi folks,

I'm upgrading the OpenBSD package to 1.4.2. All is well, but just occasionally (i.e. non-deterministically) I'm able to get kqueue-related test failures like this:

runtime: kevent on fd 13 failed with 9
fatal error: runtime: netpoll failed

runtime stack:
runtime.throw(0xd17db9, 0x17)
	/usr/local/go/src/runtime/panic.go:774 +0x72
runtime.netpoll(0x47173ead79400, 0x1)
	/usr/local/go/src/runtime/netpoll_kqueue.go:77 +0x253
runtime.startTheWorldWithSema(0xffffffffffffff00, 0x217314f58)
	/usr/local/go/src/runtime/proc.go:1083 +0x236
runtime.gcStart.func2()
	/usr/local/go/src/runtime/mgc.go:1347 +0x35
runtime.systemstack(0x2376c82f0)
	/usr/local/go/src/runtime/asm_amd64.s:370 +0x66
runtime.mstart()
	/usr/local/go/src/runtime/proc.go:1146
...

Full test output

Any ideas?

In the meantime, should this stop me from updating the package? Presumably nothing terrible will happen in the event that a kqueue fails?

Thanks!

Version Information

Syncthing Version: v1.4.2
OS Version: OpenBSD-current/amd64

Activity

  1. vext01 commented on May 3, 2020

    @vext01
    Author

    runtime: kevent on fd 13 failed with 9

    I'm guessing the 9 here is an errno.

    9 EBADF Bad file descriptor.
    
  2. vext01 commented on May 3, 2020

    @vext01
    Author

    File descriptor limit is 7030 -- the maximum the kernel allows. Hopefully we are not out of descriptors...

  3. imsodin commented on May 3, 2020

    @imsodin
    Member

    File descriptor limit is 7030 -- the maximum the kernel allows. Hopefully we are not out of descriptors...

    While it's a bit surprising in tests, in practice it's very likely given kqueue is non-recursive, i.e. a descriptor is needed for every dir in the folder (and maybe even file, didn't check). It has been a problem previously and the limit can be increased: https://forum.syncthing.net/t/high-file-descriptor-usage-openbsd/13408

    In the meantime, should this stop me from updating the package? Presumably nothing terrible will happen in the event that a kqueue fails?

    Kqueue failing wouldn't be that bad, just means error in the UI and falling back to more frequent periodic scans. However panicking is another matter, that takes the entire program down.

    Any ideas?

    Please check if after increasing kern.maxfiles this doesn't come up anymore. If yes well have to see how to integrate this: Unfortunately go doesn't provide a way to set this value (golang/go#8757), but if there's a simple way to modify this without elevated privileges it would be worth baking it into Syncthing itself, pointers appreciated. Otherwise probably through some post-install script of your packaging.

  4. vext01 commented on May 3, 2020

    @vext01
    Author

    Ah yes, I forgot about kern.maxfiles.

    Well, I upped the limit to 16000 and kqueue still occasionally fails. That should be more than enough, right?

  5. imsodin commented on May 3, 2020

    @imsodin
    Member

    Well, I upped the limit to 16000 and kqueue still occasionally fails. That should be more than enough, right?

    For tests either 7k or 16k should be enough, so the issue you see here might be something else indeed, but if I wasn't mistaken in that thread it's definitely not enough in general (https://forum.syncthing.net/t/high-file-descriptor-usage-openbsd/13408/7):

    [...] Kqueue is a “trigger type watch”, which means it needs to watch both files and directories. So it’s one fd per directory and file. [...]

    16k dirs and files is not much.

    What version of Go are you on?

  6. calmh commented on May 3, 2020

    @calmh
    Member

    The fatal error is from the net poller which is go internal and not involved in the fs watcher, although I guess bugs in one could theoretically affect the other.

  7. AudriusButkevicius commented on May 3, 2020

    @AudriusButkevicius
    Member

    Yet I think this should be a ticket with go, as the stacktrace does not even touch our code.

  8. vext01 commented on May 3, 2020

    @vext01
    Author

    16k dirs and files is not much.

    You mean I should try more?

    What version of Go are you on?

    go-1.13.9

    EDIT: Sorry, github didn't update. So if this is a go issue, I'll get our go packager involved.

  9. 4a6f656c commented on May 4, 2020

    @4a6f656c

    runtime: kevent on fd 13 failed with 9

    This is reporting an EBADF returned by a call to kevent() where fd 13 is the file descriptor previously returned by kqueue(). This would most likely be caused by the program closing the file descriptor underneath the Go runtime:

    package main
    
    import (
            "log"
            "net/http"
            "syscall"
    )
    
    func main() {
            if _, err := http.Get("https://google.com/"); err != nil {
                    log.Fatal(err)
            }
            for i := 3; i < 100; i++ {
                    if err := syscall.Close(i); err == nil {
                            log.Printf("Closed fd %d\n", i)
                    }
            }
            if _, err := http.Get("https://google.com/"); err != nil {
                    log.Fatal(err)
            }
    }
    
  10. vext01 commented on May 4, 2020

    @vext01
    Author

    Folks, if someone can tell me either: how run the tests without caching; or how to clean the sources, then I can run tests under ktrace to verify the above hypothesis.

    (Please excuse my near zero knowledge of golang).

  11. imsodin commented on May 4, 2020

    @imsodin
    Member

    To run tests regardless of caching, use -counts=1.

  12. vext01 commented on May 5, 2020

    @vext01
    Author

    Thanks!

    I added -count=1 to the test invocation in build.go and ran it in a loop until it crashed:

    runtime: kevent on fd 8 failed with 9
    fatal error: runtime: netpoll failed
    

    Full stack trace

    Using the ktrace output, I filtered on the crashing PID and eyeballed the result. Here's what I believe to be the crux of the problem:

     35253 model.test CALL  close(8)
     35253 model.test RET   close 0
     ...
     35253 model.test CALL  kevent(8,0,0,0x2fe048738,64,0x2fe048720)
     35253 model.test RET   kevent -1 errno 9 Bad file descriptor
    

    And here's the unelided snippet of the trace (syscalls seem to be interleaved; presumably threads?):

     35253 model.test CALL  close(8)
     35253 model.test RET   close 0
     35253 model.test CALL  unlink(0xc0074ddb60)
     35253 model.test NAMI  "TeCdVXnj"
     35253 model.test RET   unlink -1 errno 1 Operation not permitted
     35253 model.test CALL  rmdir(0xc0074ddb80)
     35253 model.test NAMI  "TeCdVXnj"
     35253 model.test RET   rmdir -1 errno 66 Directory not empty
     35253 model.test STRU  struct kevent { ident=34, filter=EVFILT_VNODE, flags=0x21<EV_ADD|EV_CLEAR>, fflags=0x1<NOTE_DELETE>, data=0, udata=0x0 }
     35253 model.test CALL  open(0xc0074ddb90,0x10000<O_RDONLY|O_CLOEXEC>)
     35253 model.test RET   kevent 1
     35253 model.test NAMI  "."
     35253 model.test CALL  close(34)
     35253 model.test RET   open 8
     35253 model.test CALL  fstat(8,0xc0074b97a0)
     35253 model.test RET   close 0
     35253 model.test STRU  struct stat { dev=1044, ino=5379728, mode=drwxr-xr-x , nlink=17, uid=1000<"edd">, gid=1000<"edd">, rdev=21513501, atime=1588671404<"May  5 10:36:44 2020">.373850251, mtime=1588671424<"May  5 10:37:04 2020">.683637560, ctime=1588671424<"May  5 10:37:04 2020">.683637560, size=1536, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
     35253 model.test CALL  close(34)
     35253 model.test RET   fstat 0
     35253 model.test RET   close -1 errno 9 Bad file descriptor
     35253 model.test CALL  unlinkat(8,0xc0074ddb92,0<>)
     35253 model.test CALL  kevent(3,0,0,0xc0075dff40,1,0)
     35253 model.test NAMI  "TeCdVXnj"
     35253 model.test RET   unlinkat -1 errno 1 Operation not permitted
     35253 model.test CALL  fstatat(8,0xc0074ddbb0,0xc0074b97f8,0x2<AT_SYMLINK_NOFOLLOW>)
     35253 model.test NAMI  "TeCdVXnj"
     35253 model.test STRU  struct stat { dev=1044, ino=5404751, mode=drwxr-xr-x , nlink=3, uid=1000<"edd">, gid=1000<"edd">, rdev=21613080, atime=1588671424<"May  5 10:37:04 2020">.633643491, mtime=1588671424<"May  5 10:37:04 2020">.603635746, ctime=1588671424<"May  5 10:37:04 2020">.603635746, size=512, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
     35253 model.test RET   fstatat 0
     35253 model.test CALL  openat(8,0xc0074ddbc0,0x10000<O_RDONLY|O_CLOEXEC>)
     35253 model.test NAMI  "TeCdVXnj"
     35253 model.test RET   openat 10/0xa
     35253 model.test CALL  fstat(10,0xc0074b9668)
     35253 model.test STRU  struct stat { dev=1044, ino=5404751, mode=drwxr-xr-x , nlink=3, uid=1000<"edd">, gid=1000<"edd">, rdev=21613080, atime=1588671424<"May  5 10:37:04 2020">.633643491, mtime=1588671424<"May  5 10:37:04 2020">.603635746, ctime=1588671424<"May  5 10:37:04 2020">.603635746, size=512, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
     35253 model.test RET   fstat 0
     35253 model.test CALL  getdents(10,0xc007a8a000,0x2000)
     35253 model.test RET   getdents 104/0x68
     35253 model.test CALL  getdents(10,0xc007a8a000,0x2000)
     35253 model.test RET   getdents 0
     35253 model.test CALL  unlinkat(10,0xc0074ddbe0,0<>)
     35253 model.test NAMI  ".stfolder"
     35253 model.test RET   unlinkat -1 errno 1 Operation not permitted
     35253 model.test CALL  fstatat(10,0xc0074ddbf0,0xc0074b9660,0x2<AT_SYMLINK_NOFOLLOW>)
     35253 model.test NAMI  ".stfolder"
     35253 model.test STRU  struct stat { dev=1044, ino=5404759, mode=drwxr-xr-x , nlink=2, uid=1000<"edd">, gid=1000<"edd">, rdev=21616167, atime=1588671424<"May  5 10:37:04 2020">.603635746, mtime=1588671424<"May  5 10:37:04 2020">.603635746, ctime=1588671424<"May  5 10:37:04 2020">.603635746, size=512, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
     35253 model.test RET   fstatat 0
     35253 model.test CALL  openat(10,0xc0074ddc00,0x10000<O_RDONLY|O_CLOEXEC>)
     35253 model.test NAMI  ".stfolder"
     35253 model.test RET   openat 12/0xc
     35253 model.test CALL  fstat(12,0xc0074b94d0)
     35253 model.test STRU  struct stat { dev=1044, ino=5404759, mode=drwxr-xr-x , nlink=2, uid=1000<"edd">, gid=1000<"edd">, rdev=21616167, atime=1588671424<"May  5 10:37:04 2020">.603635746, mtime=1588671424<"May  5 10:37:04 2020">.603635746, ctime=1588671424<"May  5 10:37:04 2020">.603635746, size=512, blocks=4, blksize=16384, flags=0x0, gen=0x0 }
     35253 model.test RET   fstat 0
     35253 model.test CALL  getdents(12,0xc007a90000,0x2000)
     35253 model.test RET   getdents 64/0x40
     35253 model.test CALL  getdents(12,0xc007a90000,0x2000)
     35253 model.test RET   getdents 0
     35253 model.test CALL  close(12)
     35253 model.test RET   close 0
     35253 model.test CALL  unlinkat(10,0xc0074ddc10,0x8<AT_REMOVEDIR>)
     35253 model.test NAMI  ".stfolder"
     35253 model.test RET   unlinkat 0
     35253 model.test STRU  struct kevent { ident=35, filter=EVFILT_VNODE, flags=0x21<EV_ADD|EV_CLEAR>, fflags=0x1<NOTE_DELETE>, data=0, udata=0x0 }
     35253 model.test CALL  close(10)
     35253 model.test RET   kevent 1
     35253 model.test CALL  close(35)
     35253 model.test RET   close 0
     35253 model.test CALL  unlinkat(8,0xc0074ddc20,0x8<AT_REMOVEDIR>)
     35253 model.test RET   close 0
     35253 model.test NAMI  "TeCdVXnj"
     35253 model.test CALL  close(35)
     35253 model.test RET   close -1 errno 9 Bad file descriptor
     35253 model.test CALL  kevent(3,0,0,0xc0075dff40,1,0)
     35253 model.test RET   nanosleep 0
     35253 model.test RET   nanosleep 0
     35253 model.test CALL  __thrwakeup(0xc0005ea340,1)
     35253 model.test RET   __thrwakeup 0
     35253 model.test RET   __thrsleep 0
     35253 model.test CALL  mmap(0xc007a98000,0x8000,0x3<PROT_READ|PROT_WRITE>,0x5012<MAP_PRIVATE|MAP_FIXED|MAP_ANON|MAP_STACK>,-1,0)
     35253 model.test RET   mmap 824762269696/0xc007a98000
     35253 model.test CALL  clock_gettime(CLOCK_MONOTONIC,0x2fe048f28)
     35253 model.test CALL  clock_gettime(CLOCK_REALTIME,0xc0001d0700)
     35253 model.test STRU  struct timespec { 1426931.891864080 }
     35253 model.test RET   clock_gettime 0
     35253 model.test STRU  struct timespec { 1588671424<"May  5 10:37:04 2020">.693868659 }
     35253 model.test RET   clock_gettime 0
     35253 model.test CALL  clock_gettime(CLOCK_MONOTONIC,0xc0001d0708)
     35253 model.test STRU  struct timespec { 1426931.891894096 }
     35253 model.test RET   clock_gettime 0
     35253 model.test CALL  clock_gettime(CLOCK_REALTIME,0xc0001d7700)
     35253 model.test CALL  kevent(8,0,0,0x2fe048738,64,0x2fe048720)
     35253 model.test RET   kevent -1 errno 9 Bad file descriptor
    

    So we are seeing some permission denied errors, which may or may not be related.

    Hopefully the ST devs can glean some insight from this?

  13. AudriusButkevicius commented on May 5, 2020

    @AudriusButkevicius
    Member

    This is just test failures, correct?

  14. calmh commented on May 5, 2020

    @calmh
    Member

    This test is running with the race detector, yes? Only way I could see this being "our" fault is we had a race in the tests where we open/close stuff so that we close the wrong fd somehow.

  15. vext01 commented on May 5, 2020

    @vext01
    Author

    This is just test failures, correct?

    I've not yet actually tried running this version of ST. But I can.

    Whatever we do, I'd like to be sure that there's no possibility of data loss.

    This is just test failures, correct?

    Last we spoke about the race detector, it didn't work on OpenBSD. If that's no longer the case, I'm happy to try.

    P.S. Above traces were from master by the way.

  16. 6 remaining items

  17. vext01 commented on May 11, 2020

    @vext01
    Author

    Folks, I'm keen to get to the bottom of this. Are there any STLOG flags which could help to figure out what is going on here?

    I'm going to try running syncthing-1.5.0 on one of my BSD boxes for a while and see if this comes up outside of tests. I may delve into code, but I have limited time to invest.

    Supposing this did come up outside of tests, what are the consequences? Just that syncthing stops running, right? Is there any chance of data loss?

  18. calmh commented on May 11, 2020

    @calmh
    Member

    Crashes should not cause data loss. If you can provoke it outside of tests we can look at log flags then depending on what was happening when it crashed.

    What I can say is that no user with crash reporting enabled (which is the default) has ever run into this issue, because there are zero hits on "netpoll" in our crash reporting system. (Plenty of other odd stuff though.)

  19. vext01 commented on May 11, 2020

    @vext01
    Author

    Crashes should not cause data loss. If you can provoke it outside of tests we can look at log flags then depending on what was happening when it crashed.

    OK. I may still try adding some prints in strategic locations to see if I can understand what's gone wrong.

    What I can say is that no user with crash reporting enabled (which is the default) has ever run into this issue, because there are zero hits on "netpoll" in our crash reporting system. (Plenty of other odd stuff though.)

    That's good to know, but also somewhat expected for OpenBSD users at least. Most OpenBSD users will install from our binary packages repo and we've not yet updated to the version with this problem :)

  20. vext01 commented on May 13, 2020

    @vext01
    Author

    So I cloned the notify source code and ran the tests on OpenBSD:

    arrakis:notify> go test -count=1
    PASS
    ok      github.com/syncthing/notify     18.567s
    arrakis:notify> go test -count=1
    --- FAIL: TestWatcherKqueue (0.14s)
        testing_test.go:215: testing_test.go:371: unlinkat /home/edd/source/notify/testdata/621182279/src/github.com/ppknap/link/include/coost/link: bad file descriptor
        testing_test.go:219: testing_test.go:300: w.Watcher.Close()=Not all watches were removed: len(t.pthLkp) == 3
    FAIL
    exit status 1
    FAIL    github.com/syncthing/notify     17.977s
    arrakis:notify> go test -count=1
    runtime: kevent on fd 40 failed with 9
    fatal error: runtime: netpoll failed
    ...
    

    full output

    So is this where the issue lies?

    I see that you have a fork of notify and the original author's tree (rjeczalik) may be abandoned?. Who do I raise this with?

    FWIW, I can reproduce this on both trees.

  21. calmh commented on May 13, 2020

    @calmh
    Member

    Well, we're already aware and not super likely to fix it in short order, so try upstream for one more option.

  22. vext01 commented on May 13, 2020

    @vext01
    Author

    OK. It's here:
    rjeczalik/notify#187

  23. vext01 commented on May 13, 2020

    @vext01
    Author

    Well, we're already aware

    I didn't realise that we already knew notify was at fault :P

  24. added
    not-our-bug
    on May 13, 2020
  25. calmh commented on May 13, 2020

    @calmh
    Member

    Oh, I'm not sure it has anything to do with the crash above. I read it sloppily and assumed you had reproduced the crash from the issue. Regardless, my comment is still mostly the same.

  26. vext01 commented on May 13, 2020

    @vext01
    Author
  27. vext01 commented on May 15, 2020

    @vext01
    Author

    OK, so I've been running 1.5.0 for a few days on a production node and no kevent issues. I'm probably going to move forward with the package update.

    I did spend some time reading the notify source code, but since I'm a total n00b at golang, I can't really follow. Really we'd need an interested go programmer to take a look and see what's going on.

    Would you folks mind if I open a bug bounty for this? It's bothering me. Obviously, cash out of my own pocket (and probably not a huge amount. I'm hoping this'd be a easy fix for a seasoned go programmer) 😸

  28. vext01 commented on Jul 8, 2022

    @vext01
    Author

    When updating OpenBSD package to 1.20.3 I didn't see any failure like this.

    Will close for now.

  29. added
    frozen-due-to-age
    on Jul 8, 2023
  30. locked and limited conversation to collaborators on Jul 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    frozen-due-to-agenot-our-bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions