Hi there, I've ran into an issue when working with this project.
Due to an error on my part, I've tried to access the method Sock.Pollin on a sock that was previously destroyed. Doing so resulted in a SIGABRT and a core dump from the underlying czmq lib.
Steps to reproduce
This simple example would result in a similar crash
The czmq lib calls assert (self); in the beginning of each method, which would fail when the sock has been destroyed because resources have been freed. When the assert fails, a SIGABRT is sent, which triggers the core dump.
The goczmq lib does not perform additional verification before calling the C method
// Events returns the current value of the socket's events option
func Events(s *Sock) int {
val := C.zsock_events(unsafe.Pointer(s.zsockT))
return int(val)
}
// Pollin returns true if there is a Pollin
// event on the socket
func (s *Sock) Pollin() bool {
return Events(s)&Pollin == Pollin
}
Solutions
My fix was to make sure that the case was not possible (so joining all goroutines before destroying the sock), but two solutions would make this approach more robust, as a SIGABRT is not recoverable:
Adding a way to verify that a socket has not been destroyed, as it is not possible at the moment
Adding a verification that the socket has not been destroyed during the function call, before calling the C method
The second solution might modify the Pollin signature with something like func (s *Sock) Pollin() (bool, error) which would make it easy to process errors during the Pollin call
Additional remarks
For now, I'm pretty sure this affects the Pollin and Pollout methods. I suspect that this affects all methods calling directly the C library as well, for instance RecvFrame, but I have not checked that.
Hi there, I've ran into an issue when working with this project.
Due to an error on my part, I've tried to access the method
Sock.Pollin
on a sock that was previously destroyed. Doing so resulted in aSIGABRT
and a core dump from the underlying czmq lib.Steps to reproduce
This simple example would result in a similar crash
Running this example would result in the following output:
Reason
The czmq lib calls
assert (self);
in the beginning of each method, which would fail when the sock has been destroyed because resources have been freed. When the assert fails, aSIGABRT
is sent, which triggers the core dump.The goczmq lib does not perform additional verification before calling the C method
Solutions
My fix was to make sure that the case was not possible (so joining all goroutines before destroying the sock), but two solutions would make this approach more robust, as a
SIGABRT
is not recoverable:The second solution might modify the Pollin signature with something like
func (s *Sock) Pollin() (bool, error)
which would make it easy to process errors during the Pollin callAdditional remarks
For now, I'm pretty sure this affects the
Pollin
andPollout
methods. I suspect that this affects all methods calling directly the C library as well, for instanceRecvFrame
, but I have not checked that.