summaryrefslogtreecommitdiff
path: root/vio
diff options
context:
space:
mode:
authorVladislav Vaintroub <wlad@mariadb.com>2020-08-03 13:23:38 +0200
committerVladislav Vaintroub <wlad@mariadb.com>2020-08-03 13:23:38 +0200
commitccb9f673b48ffa17103e628f34804ee1f2748b37 (patch)
treee45772806c6ffe0d7a915c09d9a31c9d7777ec8f /vio
parent4d41f316c3c1c05fdd35cbdc1b626d596b89af40 (diff)
downloadmariadb-git-ccb9f673b48ffa17103e628f34804ee1f2748b37.tar.gz
MDEV-23348 vio_shutdown does not prevent later ReadFile on named pipe
Introduce st_vio::shutdown_flag to be checked prior to Read/WriteFile and during wait for async.io to finish.
Diffstat (limited to 'vio')
-rw-r--r--vio/vio.c1
-rw-r--r--vio/viopipe.c17
2 files changed, 14 insertions, 4 deletions
diff --git a/vio/vio.c b/vio/vio.c
index 52a5387a852..694d2f7b7ff 100644
--- a/vio/vio.c
+++ b/vio/vio.c
@@ -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
diff --git a/vio/viopipe.c b/vio/viopipe.c
index 5007599aa17..aeaad311b7e 100644
--- a/vio/viopipe.c
+++ b/vio/viopipe.c
@@ -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). */
@@ -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);
@@ -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))
@@ -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);
}
@@ -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;