Nanomsg 1.1从Couchbase取数触发Signal 6中断,能否移除errno_assert而不升级版本?
errno_assert(rc >=0) in Nanomsg 1.1 without upgrading? Short answer: Yes, you can safely remove this assertion, but you should replace it with proper error handling logic instead of just deleting it outright.
Let's break down the problem and the reasoning:
Why the crash happens
Your backtrace and log show that poll() is returning an error with errno=22 (EINVAL), which triggers the errno_assert(rc >=0) in efd.c:91. This assertion is designed to abort the program when an unexpected error occurs, but clearly in your production scenario, this error is happening periodically and isn't "unexpected" enough to justify crashing the entire application.
Nanomsg 1.2 removed this assertion for good reason: hard-crashing on non-fatal poll errors isn't robust. Later versions handle these errors gracefully by propagating them back to the caller instead of triggering an abort.
How to modify the code safely
Instead of just deleting the assertion, you should mimic the approach taken in newer Nanomsg versions. Replace:
errno_assert (rc >= 0);
With code that returns the error to the caller, like:
if (rc < 0) { return -errno; }
This way, the error is propagated up to your application code (vcmNpsIcmMsgRecv() and beyond), giving you the chance to handle it—for example, retry the operation, log the error without crashing, or implement fallback logic.
Additional considerations
- Root cause investigation: Even with this fix, you should try to figure out why
poll()is returningEINVAL. Common causes include:- An invalid timeout value passed to
nn_efd_wait() - A broken or invalid event file descriptor (efd)
- System-level resource constraints that interfere with
poll()
Debugging this will help prevent the error from happening in the first place.
- An invalid timeout value passed to
- Upper layer error handling: Ensure that your application code (the functions calling into Nanomsg) can handle negative return values from these recv operations. If they're currently assuming calls always succeed, you'll need to add error checking there too.
内容的提问来源于stack exchange,提问作者arihant jain

