stability: networking layer should budget file descriptors
Version: CockroachDB CCL v1.1-beta.20170921 (linux amd64, built 2017/09/21 15:48:53, go1.8.3)
When https://github.com/cockroachdb/cockroach/issues/19171 (a file descriptor leak) was first encountered, the symptoms were that the process was using much more CPU than normal (200%), hadn't written out any logs for a day, and was completely unresponsive to all network requests on both port. There was no clue anywhere about what was wrong.
It took strace-ing to figure out what was actually happening, but users shouldn't be expected to figure this out to understand what's going on with their process if they somehow manage to get into this state.
Judging by the stack trace @mjibson copied into #19171, it's likely that most goroutines were blocked on trying to log, meaning that the goroutine with the logging mutex was presumably blocked trying to open a new log file. I believe @mjibson could provide the rest of the dump if necessary.
Some other sort of behavior would be preferable here, if possible. We obviously don't have a ton of options, but may be able to log to an existing log file that we have open if we fail to open a new one, or if worse comes to worse just crash. @mberhault, do you have any thoughts?
Ever-increase open FDs is the kind of thing we can't do too much about (other than fixing the bugs causing them).
That said, we should at the very least monitor it (sys_fd_open vs sys_fd_softlimit) and alert in prometheus. AdminUI/Log warnings when approaching the limit might be a good idea too.
I added a testing alert at 80% used.
it's likely that most goroutines were blocked on trying to log, meaning that the goroutine with the logging mutex was presumably blocked trying to open a new log file.
It doesn't retry opening a log file, does it? If it fails to open a log file it should probably just panic instead of retry (and certainly not retry while holding a singleton lock).
Ever-increase open FDs is the kind of thing we can't do too much about (other than fixing the bugs causing them).
There's no perfect solution, but giving each component of the system an FD budget and attempting to stay within it can help. We already do this for rocksdb. It's harder to do this for network connections than for files on disk, but we can stop accepting new connections on one or both ports when FD usage is above a threshold (or accept new connections and close old (ideally idle) ones, depending on what we want to prioritize).
It doesn't retry opening a log file, does it? If it fails to open a log file it should probably just panic instead of retry (and certainly not retry while holding a singleton lock).
No, we try to output an error message however we can and then exit the program.
@mjibson - we could potentially learn more about what got stuck here (e.g. to validate @bdarnell's hypothesis on the leak issue) if you share the goroutine dump.
Can you try to repro with v1.1.1, when that's released, or with master? I just backported a fix for a log mutex deadlock (https://github.com/cockroachdb/cockroach/pull/19287) that I suspect is the same one observed here.
I would if I was capable of reproducing the file descriptor leak at all
Actually, sounds like we're confident that #19171 was caused by the log mutex bug fixed in #17871. Want to leave this open to track additional file-descriptor bookkeeping work, or is #17871 good enough?
I'd leave this one open (at a low priority) to track the intention to give the networking layer some budget of file descriptors that it will stay within.
@bdarnell: this may still be something to address, re-assigning for triage.
Doesn't seem to have come up again in the last couple of years, so I'll just leave this unassigned.
Closing based on the last comment from @bdarnell, has not come up recently and no plans to work on it.