mirror of
https://github.com/gogrlx/nats-server.git
synced 2026-04-14 02:07:59 -07:00
With Go 1.12 (strangely was not able to reproduce with Go 1.11) the test TestRouteNoCrashOnAddingSubToRoute() would frequently locks up and consume all avail CPUs on the machine. Running this test with GOMAXPROCS=2 you would see server.test CPU usage pegged at 200% (assuming you have at least 2 CPUs). The reason was that the writeLoop was spinning because another routine was already in flushOutbound() and stack trace would show that it was stuck in system calls. It seems that even though the writeLoop does release the lock but grab it right away was not allowing the syscall to complete. So decided to put back the unlock/gosched/lock back in flushOutbound() when flag is already set, but then protect the closeConnection() with its own flag (similar to clearConnection) to not re-introduce issue fixed in #1092. Had to fix the benchmark test RoutedInterestGraph because after a route is accepted, the initial PING will be sent after 1sec which was breaking this test. Signed-off-by: Ivan Kozlovic <ivan@synadia.com>