Why does Dispose not wait for HttpServer to actually stop? #439

Closed
opened 2025-12-29 08:28:12 +01:00 by adam · 2 comments
Owner

Originally created by @emilpeder on GitHub (Aug 17, 2022).

Originally assigned to: @StefH on GitHub.

In the WireMockServer class:
https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Server/WireMockServer.cs

The Dispose method calls _httpServer?.StopAsync(); must does not wait for this operation to complete. Is there any reason for that?

On the contrary, the Stop method does wait.

If we want to make sure the WireMockServer is fully stopped and disposed we therefore need to call both Stop and then Dispose, is that correct?

Originally created by @emilpeder on GitHub (Aug 17, 2022). Originally assigned to: @StefH on GitHub. In the WireMockServer class: https://github.com/WireMock-Net/WireMock.Net/blob/master/src/WireMock.Net/Server/WireMockServer.cs The Dispose method calls `_httpServer?.StopAsync();` must does not wait for this operation to complete. Is there any reason for that? On the contrary, the Stop method does wait. If we want to make sure the WireMockServer is fully stopped and disposed we therefore need to call both Stop and then Dispose, is that correct?
adam added the question label 2025-12-29 08:28:12 +01:00
adam closed this issue 2025-12-29 08:28:12 +01:00
Author
Owner

@StefH commented on GitHub (Aug 17, 2022):

@emilpeder
There's no specific reason for that, other that dispose normally only cleans the resources.

But I could call Stop first.

For now you indeed need to call Stop and then Dispose it.

@StefH commented on GitHub (Aug 17, 2022): @emilpeder There's no specific reason for that, other that dispose normally only cleans the resources. But I could call Stop first. For now you indeed need to call Stop and then Dispose it.
Author
Owner

@emilpeder commented on GitHub (Aug 17, 2022):

All right. For us this was a source of confusion, since we ended up with race conditions where sometimes tests failed because the HttpServer inside WireMock was still serving requests although we had disposed the WireMockServer instance.
Thanks for the clarification.

@emilpeder commented on GitHub (Aug 17, 2022): All right. For us this was a source of confusion, since we ended up with race conditions where sometimes tests failed because the HttpServer inside WireMock was still serving requests although we had disposed the WireMockServer instance. Thanks for the clarification.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/WireMock.Net#439