[SERVER-6771] Windows Service: 'net stop mongodb' gives System error 109 has occurred. -- The pipe has been ended. Created: 15/Aug/12  Updated: 03/Jan/18  Resolved: 11/Aug/14

Status: Closed
Project: Core Server
Component/s: Packaging
Affects Version/s: 2.0.7, 2.2.0-rc1
Fix Version/s: 2.7.5

Type: Bug Priority: Major - P3
Reporter: Tad Marshall Assignee: Mark Benvenuto
Resolution: Done Votes: 12
Labels: Windows, cap-ticket-needed
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified
Environment:

Windows, mongod.exe or mongos.exe running as a service


Issue Links:
Depends
Duplicate
is duplicated by SERVER-7901 mongo services on stopping gives Erro... Closed
is duplicated by SERVER-17295 On Windows, service recovery actions ... Closed
is duplicated by SERVER-16085 Windows service: net stop MongoDB giv... Closed
Related
related to SERVER-6065 db.shutdownServer() does not work as ... Closed
related to SERVER-12875 Service doesn't stop cleanly on Windows Closed
is related to SERVER-5703 ntservice should not have to fake out... Closed
Tested
Backwards Compatibility: Fully Compatible
Operating System: Windows
Sprint: Server 2.7.5
Participants:
Case:

 Description   

When mongod.exe is installed as a service on Windows (with --install), the "net stop mongodb" command does not reply with "The Mongo DB service was stopped successfully." the way it did in version 2.1.0 but instead displays "System error 109 has occurred." and "The pipe has been ended.". This was likely broken by changes we made to our exit logic after 2.1.0 but before 2.2.0-rc1.

This error message is actually the extent of the problem – we shut down cleanly and no errors are logged in the Windows Event Log.



 Comments   
Comment by Githook User [ 07/Aug/14 ]

Author:

{u'username': u'markbenvenuto', u'name': u'Mark Benvenuto', u'email': u'mark.benvenuto@mongodb.com'}

Message: SERVER-6771: Windows Service: 'net stop mongodb' gives System error 109 has occurred. – The pipe has been ended.
SERVER-13338: NT Service does not return failure code on exit
Branch: master
https://github.com/mongodb/mongo/commit/488e855b797f1a61d6a5e08f812f85fcb2f03a51

Comment by Michael Kennedy [ 25/Mar/14 ]

I believe this is also the case on Windows 8.1 running 2.6 rc0.

Comment by Jose Medaglia [ 25/Mar/14 ]

Regarding the affected versions, this is still happening on latest MongoDB version (2.4.9 64-bit) in Windows 7

Comment by Michael Kennedy [ 07/Mar/14 ]

Nice to see this getting some attention, thanks.

Comment by Tad Marshall [ 01/Oct/12 ]

On some systems, you may see the "Error 109" from both a command line "net stop mongodb" and from a stop issued in the Services console, or you may see the error in one place and not in the other. The cause and the fix should be the same in both cases, but we'll be sure to test both when fixing this.

Comment by Tad Marshall [ 17/Aug/12 ]

The commit that fixed this broke clean shutdown. I need to prevent early exit in a different way.

Comment by auto [ 17/Aug/12 ]

Author:

{u'date': u'2012-08-17T02:48:08-07:00', u'email': u'tad@10gen.com', u'name': u'Tad Marshall'}

Message: Revert "SERVER-6771 don't exit until SCM is done with us"

This reverts commit a30fbf1c35b266c608e50a48d68d4a7a147015e8.

This change appears to have broken clean shutdown in many cases
(presumably because I skip a call to exitCleanly if a shutdown is
already in progress).
Branch: master
https://github.com/mongodb/mongo/commit/bd761d51930a8481a14664c98ae1219c858cdd02

Comment by Tad Marshall [ 16/Aug/12 ]

Fix pushed to master ... not yet to 2.2 or 2.0 branches.

Comment by auto [ 16/Aug/12 ]

Author:

{u'date': u'2012-08-16T10:56:06-07:00', u'email': u'tad@10gen.com', u'name': u'Tad Marshall'}

Message: SERVER-6771 don't exit until SCM is done with us

Stay running while the Windows Service Control Manager makes its
various callbacks and return from any callbacks we are in before
we exit with ::_exit( EXIT_CLEAN ). This lets the SCM close the
pipe itself before we go away, so it doesn't see us "end" it.
Branch: master
https://github.com/mongodb/mongo/commit/a30fbf1c35b266c608e50a48d68d4a7a147015e8

Comment by Tad Marshall [ 16/Aug/12 ]

I spent some quality time in the debugger and learned what REALLY goes on when we run as a service and then get shut down. It's a little different from what I had thought before.

When we call the Windows API StartServiceCtrlDispatcher(), that thread blocks inside the Windows Service Control Manager until it is ready to let go of us. The "start" address that we pass to this API is called on a new thread, and we proceed to do our run-as-a-service thing on that thread. The SCM wants us to RETURN from that thread, at which point it will return on the original thread and we are then free to call _exit() to prevent static destructors from doing any damage. What we CAN'T do is exit from the callback thread, at least if we want to keep the SCM happy.

Generated at Thu Feb 08 03:12:39 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.