-
Notifications
You must be signed in to change notification settings - Fork 594
Use pipe to properly block clients when server hasn't entered event loop. #1541
Conversation
server hasn't entered event loop.
::usleep(1000); | ||
// choose an arbitrary number for ``sent'' as token | ||
int recv, sent = 19583; | ||
if (pipe(fds) < 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use ::pipe().
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved via 0238865
|
||
// block clients from reading from server using pipe | ||
read(fds[0], &recv, sizeof(int)); | ||
if (recv != sent) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need to check the value, we only have one reader and one writer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved via 593f35a
Good one! Thanks for fixing this. |
@@ -35,7 +36,7 @@ static const sp_uint32 SERVER_PORT = 60000; | |||
|
|||
extern void start_http_client(sp_uint32 _port, sp_uint64 _requests, sp_uint32 _nkeys); | |||
|
|||
extern void start_http_server(sp_uint32 _port, sp_uint32 _nkeys); | |||
extern void start_http_server(sp_uint32 _port, sp_uint32 _nkeys, int fd, int sent); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'sent' is no longer needed either.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
resolved via dc18567
Looks good to me. |
Should fix #1544. |
The previous way of using
usleep
cannot guarantee the clients are blocked when server hasn't entered event loop, which makesheron/common/tests/cpp/network:http_unittest
flaky.This PR switches to using pipe. Server will send a byte to pipe prior to entering event loop. Clients will wait(block) until the byte is read on the other side of the pipe. This makes sure that clients are properly blocked.
Test done via script
Thanks @congwang for suggestions.