herenickname
herenickname12mo ago

Deno.serve() with SSL cert timeout

I have a very simple script that serves a /ping route. After some time (randomly) it stalls and no new request goes through. main.ts:
import { Hono } from 'https://deno.land/x/hono@v3.11.10/mod.ts'
import { basicAuth, logger } from 'https://deno.land/x/hono@v3.11.10/middleware.ts'

const app = new Hono()

app.use('*', logger())

app.get(
'/ping',
(c) => c.text('pong')
)

const cert = await Deno.readTextFile('/root/fullchain.pem')
const key = await Deno.readTextFile('/root/privkey.pem')

Deno.serve({ port: 443, cert, key }, app.fetch)
import { Hono } from 'https://deno.land/x/hono@v3.11.10/mod.ts'
import { basicAuth, logger } from 'https://deno.land/x/hono@v3.11.10/middleware.ts'

const app = new Hono()

app.use('*', logger())

app.get(
'/ping',
(c) => c.text('pong')
)

const cert = await Deno.readTextFile('/root/fullchain.pem')
const key = await Deno.readTextFile('/root/privkey.pem')

Deno.serve({ port: 443, cert, key }, app.fetch)
curl response:
# curl -v https://localhost
* Trying 127.0.0.1:443...
* Connected to localhost (127.0.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* SSL connection timeout
* Closing connection 0
curl: (28) SSL connection timeout
# curl -v https://localhost
* Trying 127.0.0.1:443...
* Connected to localhost (127.0.0.1) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* CAfile: /etc/ssl/certs/ca-certificates.crt
* CApath: /etc/ssl/certs
* TLSv1.0 (OUT), TLS header, Certificate Status (22):
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* SSL connection timeout
* Closing connection 0
curl: (28) SSL connection timeout
Can it be caused by something unstable inside Deno.serve?
# deno -V
deno 1.39.1
# deno -V
deno 1.39.1
1 Reply
Deno AI Helper
Deno AI Helper12mo ago
I wasn't able to find the answer to your question in the official Deno documentation. However, based on the code snippet you provided, I can offer some general advice, but please note that this advice is not based on the Deno documentation, and you should double-check the accuracy of the advice given. In your main.ts script, you are using Deno.serve to start an HTTPS server by providing a cert and key. The syntax for using Deno.serve looks correct, and you are correctly awaiting the reading of the certificate and key files. One thing to note is that you are using the Hono framework, and you are passing app.fetch to Deno.serve. Make sure that app.fetch is the correct method to handle the incoming requests for the Hono framework. If app.fetch is not a method provided by Hono, this could potentially cause issues. Additionally, since the issue occurs randomly after some time, it might not be directly related to the syntax or the way you are using Deno.serve. It could be related to network issues, resource limitations, or other environmental factors that are not immediately apparent from the code snippet. If the problem persists, you might want to look into the following: - Check the server logs for any errors or warnings that might indicate what is causing the timeout. - Monitor the server's resource usage to see if there's a memory leak or if the server is running out of resources. - Ensure that the server's firewall or any other network configurations are not interfering with the SSL/TLS connections. Remember to always refer to the official Deno documentation and the Hono framework documentation for the most accurate and up-to-date information.