Steve
Steve7mo ago

Leaking operation op_http_close in tests

I tried to update my repositories from Deno 1.38.1 to 1.38.4. After the update my test keeps failing with the error message "1 async operation to op_http_close was started in this test, but never completed.". I tried every version in between but had to revert to 1.38.1. Failing CI run: https://github.com/sgohlke/deno-web/actions/runs/7092893428/job/19305155074 Revert to Deno 1.38.1 is green: https://github.com/sgohlke/deno-web/actions/runs/7092893428 Failing test: https://github.com/sgohlke/deno-web/blob/main/response/responseFunctions_test.ts#L34 I use AbortController to send an AbortSignal to the server. I tried to add the finished function and console.log like in the example on https://deno.land/api@v1.38.4?s=Deno.serve , it did not help. I also tried to store the server in a const and call "await server.shutdown()", but this results in TS error "TS2339 [ERROR]: Property 'shutdown' does not exist on type 'HttpServer'." Does anyone have an idea how to fix this issue?
GitHub
Use action workflow · sgohlke/deno-web@59a6c5c
Webserver and helper functions in Deno. Contribute to sgohlke/deno-web development by creating an account on GitHub.
GitHub
Use action workflow · sgohlke/deno-web@59a6c5c
Webserver and helper functions in Deno. Contribute to sgohlke/deno-web development by creating an account on GitHub.
Deno
Deno.serve | Runtime APIs | Deno
Serves HTTP requests with the given handler.
GitHub
deno-web/response/responseFunctions_test.ts at main · sgohlke/deno-...
Webserver and helper functions in Deno. Contribute to sgohlke/deno-web development by creating an account on GitHub.
6 Replies
Deno AI Helper
Deno AI Helper7mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the information you've provided in your message, I can offer some general advice that might help you address the issue. From what you've described, it seems like there might be an asynchronous operation related to op_http_close that is not being properly awaited or closed in your tests. This can happen if the server is still running or if there are pending requests that have not been handled when the test completes. Regarding the TS2339 error you're encountering when trying to call await server.shutdown(), it's possible that the HttpServer type does not have a shutdown method in the version of Deno you are using. This could be due to a change in the API or a discrepancy between the documentation and the actual implementation. Here are a few things you could check or try: 1. Ensure that you are properly closing the server after the test. This might involve calling a method to stop the server or ensuring that all connections are closed. 2. If you're using an AbortController to signal the server to stop, make sure that the signal is being handled correctly and that it actually leads to the server shutting down. 3. Double-check the Deno documentation for the version you are using to see if there have been any changes to the HttpServer API that might affect how the server should be shut down. Please note that this advice is not based on the Deno documentation, and I recommend double-checking the accuracy of the advice given. If you continue to experience issues, you might want to consider reaching out to the Deno community for further assistance or looking for recent changes in the Deno release notes that might explain the behavior you're observing.
Leokuma
Leokuma7mo ago
I think you can open an issue and paste your test code there. There have been some questions about the new sanitizers, and some of them were actually bugs
bartlomieju
bartlomieju7mo ago
CC @mmastrac
mmastrac
mmastrac7mo ago
It looks like you need to get the return value from Deno.serve and await server.finished. The combination of fetch + serve requires this as there's a cached connection running in the background and we need to wait for it all to get torn down after the abort controller fires. You can also use the asyncDispose functionality via using, which IIRC is using _server = Deno.serve which should trigger and wait on shutdown when the block ends
Steve
Steve7mo ago
Thank you, the test is now green again. I also tried calling await server.finished before abortController.abort , as you stated first calling abort then finished fixed the problem. I'm not familiar with using yet, will try this out later.