PGM receiver crash fix (#3226)

Problem: PGM receiver can crash due to race

Solution: do not run in_event until restart_input finishes correctly.

Signed-off-by: answeroo <jiming@yafco.com>
This commit is contained in:
answeroo 2018-08-20 01:10:51 +08:00 committed by Luca Boccassi
parent 1c5e81788e
commit 7852a6ce98

View File

@ -163,6 +163,11 @@ const char *zmq::pgm_receiver_t::get_endpoint () const
void zmq::pgm_receiver_t::in_event ()
{
// If active_tsi is not null, there is a pending restart_input.
// Keep the internal state as is so that restart_input would process the right data
if (active_tsi) {
return;
}
// Read data from the underlying pgm_socket.
const pgm_tsi_t *tsi = NULL;
@ -176,9 +181,10 @@ void zmq::pgm_receiver_t::in_event ()
while (true) {
// Get new batch of data.
// Note the workaround made not to break strict-aliasing rules.
insize = 0;
void *tmp = NULL;
ssize_t received = pgm_socket.receive (&tmp, &tsi);
inpos = (unsigned char *) tmp;
// No data to process. This may happen if the packet received is
// neither ODATA nor ODATA.
@ -212,6 +218,7 @@ void zmq::pgm_receiver_t::in_event ()
}
insize = static_cast<size_t> (received);
inpos = (unsigned char *) tmp;
// Read the offset of the fist message in the current packet.
zmq_assert (insize >= sizeof (uint16_t));