Bug #31621 Windows server hanging during shutdown using named pipes and idle connection
Submitted: 15 Oct 2007 22:37 Modified: 18 Dec 2009 20:22
Reporter: Miguel Solorzano Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: General Severity:S3 (Non-critical)
Version:5.0/5.1 OS:Microsoft Windows
Assigned to: Vladislav Vaintroub CPU Architecture:Any
Tags: named pipes, shutdown

[15 Oct 2007 22:37] Miguel Solorzano
Description:
Start the server enabling named pipes:

c:\dev\5.1>bin\mysqld --standalone --console --enable-named-pipe
071015 20:20:36  InnoDB: Started; log sequence number 0 46409
071015 20:20:36 [Note] Event Scheduler: Loaded 0 events
071015 20:20:36 [Note] bin\mysqld: ready for connections.
Version: '5.1.23-beta-nt'  socket: ''  port: 3306  Source distribution

Connect with mysql.exe client using named pipes:

c:\dev\5.1>bin\mysql -uroot -W
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.23-beta-nt Source distribution

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> show variables like "%pipe%";
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| named_pipe    | ON    |
+---------------+-------+
1 row in set (0.00 sec)

Left the above connection idle.

Do the shutdown:

c:\dev\5.1>bin\mysqladmin -uroot shutdown

c:\dev\5.1>

While the prior connection is idle the server hangs during the shutdown
trying to close that connection:

071015 20:23:45 [Note] Event Scheduler: Purging the queue. 0 events
071015 20:23:47 [Warning] bin\mysqld: Forcing close of thread 1  user: 'root'

If that connection tries to query the server, then the shutdown process is
completed:

071015 20:26:17  InnoDB: Starting shutdown...
071015 20:26:18  InnoDB: Shutdown completed; log sequence number 0 46409
071015 20:26:18 [Note] bin\mysqld: Shutdown complete

How to repeat:
See description.

Suggested fix:
-
[29 Oct 2007 14:25] Timour Katchaounov
Not a feature request, so P3.
[2 Oct 2008 13:50] MySQL Verification Team
Work-around is to query the server.
[24 Sep 2009 12:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/84481
[24 Sep 2009 12:24] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/84482
[24 Sep 2009 14:03] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/84508

2814 Vladislav Vaintroub	2009-09-24
      Bug#47571: idle named pipe connection is unkillable
      Bug#31621: Windows server hanging during shutdown using named pipes 
                 and idle connection
      
      Problem: when idle pipe connection is forcefully closed with KILL
      statement or when the server goes down, thread that is closing connection
      would hang infinitely in CloseHandle(). The reason for the hang is that 
      named pipe operations are performed synchronously. In this mode all IOs
      on pipe are serialized, that is CloseHandle() will not abort ReadFile() 
      in another thread, but wait for ReadFile() to complete.
      
      The fix implements asynchrnous mode for named pipes, where operation of file
      are not synchronized. Read/Write operation would fire an async IO and wait for
      either IO completion or timeout.
      
      Note, that with this patch timeouts are properly handled for named pipes.
     @ include/violite.h
        Add pipe_overlapped to Vio structure for async IO for named pipes.
     @ sql-common/client.c
        Use async IO for named pipes.
     @ sql/mysqld.cc
        Use asynchronous pipe IO.
     @ vio/vio.c
        pass NET structure to vio_new_win32pipe 
        (it contains timeout values that are used in
        vio_read_pipe/vio_write_pipe)
     @ vio/viosocket.c
        Use async IO for named pipes.
        After issuing IO, wait for either IO completion, pipe_close_event
        or timeout.
[29 Oct 2009 17:10] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/88636

2829 Vladislav Vaintroub	2009-10-29
      Bug#47571: idle named pipe connection is unkillable
      Bug#31621: Windows server hanging during shutdown using named pipes 
                       and idle connection
            
      Problem: when idle pipe connection is forcefully closed with KILL
      statement or when the server goes down, thread that is closing connection
      would hang infinitely in CloseHandle(). The reason for the hang is that 
      named pipe operations are performed synchronously. In this mode all IOs
      on pipe are serialized, that is CloseHandle() will not abort ReadFile() 
      in another thread, but wait for ReadFile() to complete.
            
      The fix implements asynchrnous mode for named pipes, where operation of file
      are not synchronized. Read/Write operation would fire an async IO and wait for
      either IO completion or timeout.
            
      Note, that with this patch timeouts are properly handled for named pipes.
     @ include/violite.h
        Add pipe_overlapped to Vio structure for async IO for named pipes.
     @ sql-common/client.c
        Use asynchronous pipe IO.
     @ sql/mysqld.cc
        Use asynchronous pipe IO.
     @ vio/vio.c
        pass NET structure to vio_new_win32pipe 
        (it contains timeout values that are used in
        vio_read_pipe/vio_write_pipe)
     @ vio/viosocket.c
        Use async IO for named pipes.
        After issuing IO, wait for either IO completion, pipe_close_event
        or timeout.
[30 Oct 2009 9:46] Magnus BlÄudd
Review mail sent, a few comments that need to be clarified.
[30 Oct 2009 19:57] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/88803

2829 Vladislav Vaintroub	2009-10-30
      Bug#47571: idle named pipe connection is unkillable
      Bug#31621: Windows server hanging during shutdown using named pipes 
                       and idle connection
            
      Problem: when idle pipe connection is forcefully closed with KILL
      statement or when the server goes down, thread that is closing connection
      would hang infinitely in CloseHandle(). The reason for the hang is that 
      named pipe operations are performed synchronously. In this mode all IOs
      on pipe are serialized, that is CloseHandle() will not abort ReadFile() 
      in another thread, but wait for ReadFile() to complete.
            
      The fix implements asynchrnous mode for named pipes, where operation of file
      are not synchronized. Read/Write operation would fire an async IO and wait for
      either IO completion or timeout.
            
      Note, that with this patch timeouts are properly handled for named pipes.
      
      Post-review: Win32 timeout code has been fixed for named pipes and shared
      memory. We do not store pointer to NET in vio structure, only the read and 
      write timeouts.
     @ include/violite.h
        Add pipe_overlapped to Vio structure for async IO for named pipes.
     @ sql-common/client.c
        Use asynchronous pipe IO.
     @ sql/mysqld.cc
        Use asynchronous pipe IO.
     @ vio/vio.c
        -Refactor timeouts for win32 protocols: shared memory and named pipes.
        Store read/write timeout in VIO structure, instead of storing pointer
        to NET. New function vio_win32_timeout called indirectly via 
        vio_timeout changes these values.
        
        -Initialize Overlapped for use in named pipe async IO.
     @ vio/vio_priv.h
        Remove vio_ignore_timeout.
        Add vio_win32_timeout to be used for named pipes and shared memory.
     @ vio/viosocket.c
        Use async IO for named pipes.
        After issuing IO, wait for either IO completion, pipe_close_event
        or timeout.
        
        Refactor timeouts for named pipe and shared memory.
[2 Nov 2009 22:20] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/89010

3156 Vladislav Vaintroub	2009-11-02
      Bug#47571: idle named pipe connection is unkillable
      Bug#31621: Windows server hanging during shutdown using named pipes 
                 and idle connection
                  
      Problem: when idle pipe connection is forcefully closed with KILL
      statement or when the server goes down, thread that is closing connection
      would hang infinitely in CloseHandle(). The reason for the hang is that 
      named pipe operations are performed synchronously. In this mode all IOs
      on pipe are serialized, that is CloseHandle() will not abort ReadFile() 
      in another thread, but wait for ReadFile() to complete.
                  
      The fix implements asynchrnous mode for named pipes, where operation of file
      are not synchronized. Read/Write operation would fire an async IO and wait for
      either IO completion or timeout.
                  
      Note, that with this patch timeouts are properly handled for named pipes.
            
      Post-review: Win32 timeout code has been fixed for named pipes and shared
      memory. We do not store pointer to NET in vio structure, only the read and 
      write timeouts.
     @ include/violite.h
        Add pipe_overlapped to Vio structure for async IO for named pipes.
     @ sql-common/client.c
        Use asynchronous pipe IO.
     @ sql/mysqld.cc
        Use asynchronous pipe IO.
     @ vio/vio.c
        -Refactor timeouts for win32 protocols: shared memory and named pipes.
        Store read/write timeout in VIO structure, instead of storing pointer
        to NET. New function vio_win32_timeout called indirectly via 
        vio_timeout changes these values.
     @ vio/vio_priv.h
        Remove vio_ignore_timeout.
        Add vio_win32_timeout to be used for named pipes and shared memory.
     @ vio/viosocket.c
        Use async IO for named pipes.
        After issuing IO, wait for either IO completion, pipe_close_event
        or timeout.
                
        Refactor timeouts for named pipe and shared memory.
[3 Nov 2009 1:02] Vladislav Vaintroub
pushed to 5.1-bugteam, next-mr-bugfixing, mysql-pe
[4 Nov 2009 9:27] Bugs System
Pushed into 5.1.41 (revid:joro@sun.com-20091104092152-qz96bzlf2o1japwc) (version source revid:kristofer.pettersson@sun.com-20091103162305-08l4gkeuif2ozsoj) (merge vers: 5.1.41) (pib:13)
[6 Nov 2009 1:30] Paul DuBois
Noted in 5.1.41 changelog.

On WIndows, when an idle named pipe connection was forcibly closed
with a KILL statement or because the server was being shut down, the
thread that was closing the connection would hang infinitely.

Setting report to NDI pending push to 5.5.x.
[11 Nov 2009 6:55] Bugs System
Pushed into 6.0.14-alpha (revid:alik@sun.com-20091110093407-rw5g8dys2baqkt67) (version source revid:alik@sun.com-20091109080109-7dxapd5y5pxlu08w) (merge vers: 6.0.14-alpha) (pib:13)
[11 Nov 2009 7:03] Bugs System
Pushed into 5.5.0-beta (revid:alik@sun.com-20091109115615-nuohp02h8mdrz8m2) (version source revid:alik@sun.com-20091105091401-4fwfzjh1rldc6esy) (merge vers: 5.5.0-beta) (pib:13)
[11 Nov 2009 14:32] Paul DuBois
Noted in 5.5.0, 6.0.14 changelogs.
[18 Dec 2009 10:37] Bugs System
Pushed into 5.1.41-ndb-7.1.0 (revid:jonas@mysql.com-20091218102229-64tk47xonu3dv6r6) (version source revid:jonas@mysql.com-20091218095730-26gwjidfsdw45dto) (merge vers: 5.1.41-ndb-7.1.0) (pib:15)
[18 Dec 2009 10:53] Bugs System
Pushed into 5.1.41-ndb-6.2.19 (revid:jonas@mysql.com-20091218100224-vtzr0fahhsuhjsmt) (version source revid:jonas@mysql.com-20091217101452-qwzyaig50w74xmye) (merge vers: 5.1.41-ndb-6.2.19) (pib:15)
[18 Dec 2009 11:07] Bugs System
Pushed into 5.1.41-ndb-6.3.31 (revid:jonas@mysql.com-20091218100616-75d9tek96o6ob6k0) (version source revid:jonas@mysql.com-20091217154335-290no45qdins5bwo) (merge vers: 5.1.41-ndb-6.3.31) (pib:15)
[18 Dec 2009 11:22] Bugs System
Pushed into 5.1.41-ndb-7.0.11 (revid:jonas@mysql.com-20091218101303-ga32mrnr15jsa606) (version source revid:jonas@mysql.com-20091218064304-ezreonykd9f4kelk) (merge vers: 5.1.41-ndb-7.0.11) (pib:15)
[13 Jan 2011 16:40] Paul DuBois
Addition to changelog entry:

As a result of the work done for this bug, the net_read_timeout and
net_write_timeout system variables now apply to connections over all
transports, not just to TCP/IP.
[16 Feb 2011 16:08] MySQL Verification Team
See http://bugs.mysql.com/bug.php?id=60141.