Modify

Ticket #2570 (closed Bugs: fixed)

Opened 5 years ago

Last modified 5 years ago

boost::interprocess::message_queue::timed_send and timed_receive bug

Reported by: Tony Astolfi <aastolfi@…> Owned by: igaztanaga
Milestone: Boost 1.38.0 Component: interprocess
Version: Boost 1.37.0 Severity: Showstopper
Keywords: Cc:

Description

In boost::interprocess::message_queue, the timed_send and timed_receive methods may return true without actually performing the send or receive operation.

The problem lies in boost/interprocess/ipc/message_queue.hpp, in the logic that handles blocking behavior for these two methods. Both implementations have the same form:

if (<operation-would-block>) {

switch(block){

... case timed : do{

if(!<condition-variable>.timed_wait(lock, abs_time))

return !<operation-would-block>;

} while (<operation-would-block>); break; ...

}

}

The problem is that when timed_wait returns false, it might be possible to complete the operation without blocking (i.e. there might be something in the queue in the case of receive, or the queue might not be full in the case of send). Therefore, in rare cases, timed_send/timed_receive return true, without having actually done any work.

My proposed fix is to change the timed case to:

do{

if(!<condition-variable>.timed_wait(lock, abs_time)) {

if(<operation-would-block>) {

return false;

} break;

}

} while (<operation-would-block>);

After I apply this change to my own boost install, the problem disappears.

I observed this bug on Linux (some Debian 4 flavor, 32-bit)

Attachments

Change History

comment:1 follow-up: ↓ 2 Changed 5 years ago by igaztanaga

  • Status changed from new to closed
  • Resolution set to fixed

Fixed in revision 50146

comment:2 in reply to: ↑ 1 Changed 5 years ago by Tony Astolfi <aastolfi@…>

  • Status changed from closed to reopened
  • Resolution fixed deleted

Replying to igaztanaga:

Fixed in revision 50146

Fix for timed_send looks good.

Fix for timed_receive is missing curly-braces around the outer if body.

comment:3 Changed 5 years ago by igaztanaga

  • Status changed from reopened to closed
  • Resolution set to fixed

Sorry! Fixed in revision 50194.

View

Add a comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
The resolution will be deleted. Next status will be 'reopened'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.