Skip to content

Commit

Permalink
MDEV-23348 vio_shutdown does not prevent later ReadFile on named pipe
Browse files Browse the repository at this point in the history
Introduce st_vio::shutdown_flag to be checked prior to Read/WriteFile
and during wait for async.io to finish.
  • Loading branch information
vaintroub committed Aug 3, 2020
1 parent 4d41f31 commit ccb9f67
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions include/violite.h
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ struct st_vio
OVERLAPPED overlapped;
DWORD read_timeout_ms;
DWORD write_timeout_ms;
int shutdown_flag;
#endif
};
#endif /* vio_violite_h_ */
1 change: 1 addition & 0 deletions vio/vio.c
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ int vio_shared_memory_shutdown(Vio *vio, int how)

int vio_pipe_shutdown(Vio *vio, int how)
{
vio->shutdown_flag= how;
return CancelIoEx(vio->hPipe, NULL);
}
#endif
Expand Down
17 changes: 13 additions & 4 deletions vio/viopipe.c
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ size_t vio_read_pipe(Vio *vio, uchar *buf, size_t count)
size_t ret= (size_t) -1;
DBUG_ENTER("vio_read_pipe");

if (vio->shutdown_flag)
return ret;

disable_iocp_notification(&vio->overlapped);

/* Attempt to read from the pipe (overlapped I/O). */
Expand All @@ -85,8 +88,11 @@ size_t vio_read_pipe(Vio *vio, uchar *buf, size_t count)
}
/* Read operation is pending completion asynchronously? */
else if (GetLastError() == ERROR_IO_PENDING)
{
if (vio->shutdown_flag)
CancelIo(vio->hPipe);
ret= wait_overlapped_result(vio, vio->read_timeout);

}
enable_iocp_notification(&vio->overlapped);

DBUG_RETURN(ret);
Expand All @@ -99,6 +105,8 @@ size_t vio_write_pipe(Vio *vio, const uchar *buf, size_t count)
size_t ret= (size_t) -1;
DBUG_ENTER("vio_write_pipe");

if (vio->shutdown_flag == SHUT_RDWR)
return ret;
disable_iocp_notification(&vio->overlapped);
/* Attempt to write to the pipe (overlapped I/O). */
if (WriteFile(vio->hPipe, buf, (DWORD)count, &transferred, &vio->overlapped))
Expand All @@ -108,8 +116,11 @@ size_t vio_write_pipe(Vio *vio, const uchar *buf, size_t count)
}
/* Write operation is pending completion asynchronously? */
else if (GetLastError() == ERROR_IO_PENDING)
{
if (vio->shutdown_flag == SHUT_RDWR)
CancelIo(vio->hPipe);
ret= wait_overlapped_result(vio, vio->write_timeout);

}
enable_iocp_notification(&vio->overlapped);
DBUG_RETURN(ret);
}
Expand All @@ -129,9 +140,7 @@ int vio_close_pipe(Vio *vio)
BOOL ret;
DBUG_ENTER("vio_close_pipe");

CancelIo(vio->hPipe);
CloseHandle(vio->overlapped.hEvent);
DisconnectNamedPipe(vio->hPipe);
ret= CloseHandle(vio->hPipe);

vio->type= VIO_CLOSED;
Expand Down

0 comments on commit ccb9f67

Please sign in to comment.