Skip to content

Commit 01d994b

Browse files
committed
Post-fix 567c097
Do *not* check if socket is closed by another thread. This is race-condition prone, unnecessary, and harmful. VIO state was introduced to debug the errors, not to change the behavior. Rather than checking if socket is closed, add a DBUG_ASSERT that it is *not* closed, because this is an actual logic error, and can potentially lead to all sorts of funny behavior like writing error packets to Innodb files. Unlike closesocket(), shutdown(2) is not actually race-condition prone, and it breaks poll() and read(), and it worked for longer than a decade, and it does not need any state check in the code.
1 parent 50715bd commit 01d994b

File tree

1 file changed

+4
-21
lines changed

1 file changed

+4
-21
lines changed

vio/viosocket.c

Lines changed: 4 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -560,8 +560,7 @@ vio_should_retry(Vio *vio)
560560
DBUG_ENTER("vio_should_retry");
561561
DBUG_PRINT("info", ("vio_errno: %d state: %d",
562562
vio_errno(vio), (int) vio->state));
563-
DBUG_RETURN(vio_errno(vio) == SOCKET_EINTR &&
564-
vio->state < VIO_STATE_SHUTDOWN);
563+
DBUG_RETURN(vio_errno(vio) == SOCKET_EINTR);
565564
}
566565

567566

@@ -931,14 +930,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
931930
(int) mysql_socket_getfd(vio->mysql_socket),
932931
timeout));
933932

934-
if (vio->state >= VIO_STATE_SHUTDOWN)
935-
{
936-
DBUG_PRINT("info", ("vio deactivated. state: %ld", (int) vio->state));
937-
/* Socket is shutdown or closed */
938-
errno= EIO;
939-
DBUG_RETURN(-1);
940-
}
941-
933+
DBUG_ASSERT(vio->state != VIO_STATE_CLOSED);
942934
memset(&pfd, 0, sizeof(pfd));
943935

944936
pfd.fd= sd;
@@ -999,14 +991,7 @@ int vio_io_wait(Vio *vio, enum enum_vio_io_event event, int timeout)
999991
fd_set readfds, writefds, exceptfds;
1000992
MYSQL_SOCKET_WAIT_VARIABLES(locker, state) /* no ';' */
1001993
DBUG_ENTER("vio_io_wait");
1002-
1003-
if (vio->state >= VIO_STATE_SHUTDOWN)
1004-
{
1005-
DBUG_PRINT("info", ("vio deactive. state: %ld", (int) vio->state));
1006-
/* Socket is shutdown or closed */
1007-
errno= EIO;
1008-
DBUG_RETURN(-1);
1009-
}
994+
DBUG_ASSERT(vio->state != VIO_STATE_CLOSED);
1010995

1011996
/* Convert the timeout, in milliseconds, to seconds and microseconds. */
1012997
if (timeout >= 0)
@@ -1180,9 +1165,7 @@ my_bool vio_is_connected(Vio *vio)
11801165
{
11811166
uint bytes= 0;
11821167
DBUG_ENTER("vio_is_connected");
1183-
1184-
if (vio->state >= VIO_STATE_SHUTDOWN)
1185-
DBUG_RETURN(FALSE);
1168+
DBUG_ASSERT(vio->state != VIO_STATE_CLOSED);
11861169

11871170
/*
11881171
The first step of detecting an EOF condition is verifying

0 commit comments

Comments
 (0)