Skip to content

Commit ccb9f67

Browse files
committed
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.
1 parent 4d41f31 commit ccb9f67

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

include/violite.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,7 @@ struct st_vio
281281
OVERLAPPED overlapped;
282282
DWORD read_timeout_ms;
283283
DWORD write_timeout_ms;
284+
int shutdown_flag;
284285
#endif
285286
};
286287
#endif /* vio_violite_h_ */

vio/vio.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ int vio_shared_memory_shutdown(Vio *vio, int how)
6868

6969
int vio_pipe_shutdown(Vio *vio, int how)
7070
{
71+
vio->shutdown_flag= how;
7172
return CancelIoEx(vio->hPipe, NULL);
7273
}
7374
#endif

vio/viopipe.c

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ size_t vio_read_pipe(Vio *vio, uchar *buf, size_t count)
7575
size_t ret= (size_t) -1;
7676
DBUG_ENTER("vio_read_pipe");
7777

78+
if (vio->shutdown_flag)
79+
return ret;
80+
7881
disable_iocp_notification(&vio->overlapped);
7982

8083
/* 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)
8588
}
8689
/* Read operation is pending completion asynchronously? */
8790
else if (GetLastError() == ERROR_IO_PENDING)
91+
{
92+
if (vio->shutdown_flag)
93+
CancelIo(vio->hPipe);
8894
ret= wait_overlapped_result(vio, vio->read_timeout);
89-
95+
}
9096
enable_iocp_notification(&vio->overlapped);
9197

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

108+
if (vio->shutdown_flag == SHUT_RDWR)
109+
return ret;
102110
disable_iocp_notification(&vio->overlapped);
103111
/* Attempt to write to the pipe (overlapped I/O). */
104112
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)
108116
}
109117
/* Write operation is pending completion asynchronously? */
110118
else if (GetLastError() == ERROR_IO_PENDING)
119+
{
120+
if (vio->shutdown_flag == SHUT_RDWR)
121+
CancelIo(vio->hPipe);
111122
ret= wait_overlapped_result(vio, vio->write_timeout);
112-
123+
}
113124
enable_iocp_notification(&vio->overlapped);
114125
DBUG_RETURN(ret);
115126
}
@@ -129,9 +140,7 @@ int vio_close_pipe(Vio *vio)
129140
BOOL ret;
130141
DBUG_ENTER("vio_close_pipe");
131142

132-
CancelIo(vio->hPipe);
133143
CloseHandle(vio->overlapped.hEvent);
134-
DisconnectNamedPipe(vio->hPipe);
135144
ret= CloseHandle(vio->hPipe);
136145

137146
vio->type= VIO_CLOSED;

0 commit comments

Comments
 (0)