I’ve got a CapnP-based server program running on a Raspberry Pi 4. It’s written in C++, using CapnP 0.9.1. It’s single-threaded; the main() function just sets up a listener, calls kj::NEVER_DONE.wait, and stays there.
It works fine, except that every few weeks it stops accepting connections; it either doesn’t accept the incoming socket at all or never reads from it, I can’t tell which; all I see is that the client times out and gives up after 15 seconds. Then I have to kill and relaunch the server, after which it works fine again for a while.
The server process itself isn’t hung; it’s in epoll waiting for events. I attached gdb and got this backtrace:
#0 0xb6b8563c in epoll_wait (epfd=7, events=0xbecb4210, maxevents=16, timeout=-1)
#1 0x0052edcc in kj::UnixEventPort::doEpollWait (this=0x1fed420, timeout=-1)
#2 0x0052e58c in kj::UnixEventPort::wait (this=0x1fed420)
#3 0x00487744 in kj::EventLoop::wait (this=0x1fed4e0)
#4 0x00488460 in kj::_::waitImpl (node=..., result=..., waitScope=…)
#5 0x00488bd8 in kj::_::NeverDone::wait (this=0x72d3c0 <kj::NEVER_DONE>, waitScope=…)
…
The last line in the log shows that it received a connection from some unknown IPv4 address which geolocates to Russia (this happens a few times a day; the server’s on my home LAN but exposes a public port and I assume these are random hackers looking for vulns.) This connection never did anything, not surprisingly since I doubt hackers are expecting anything other than HTTP, but the logs show the socket never closed. And sure enough, if I run `lsof` I see an open TCP port from that address. (Which has been open for at least 24 hours, strangely; doesn’t the disconnect idle TCP connections after 90 minutes?)
I’m not sure what to do about this. I assume CapnP is capable of handling multiple incoming connections, so this idle socket won’t block others from connecting, right? But if not, then why isn’t it accepting any connections?
—Jens