sasa1977 / site_encrypt

Integrated certification via Let's encrypt for Elixir-powered sites
MIT License
462 stars 33 forks source link

Failure while closing HTTP connection #59

Open shiroyasha opened 1 month ago

shiroyasha commented 1 month ago

First of all, excellent work on this library. Thank you for investing your time an energy into it. πŸ™‡

I've been trying to set it up for our project, but I'm hitting a problem that I either don't understand, or it is a bug.

It is connected to this line in the API client: https://github.com/sasa1977/site_encrypt/blob/master/lib/site_encrypt/http_client.ex#L50.

Here is what happens:

  1. I start a local development server
  2. The local ACME server boots up
  3. site_encrypt tries to create a new account
  4. It runs HttpClient.request
  5. Everything works as expected (I've verified this by adding exhaustive IO.inspects to https://github.com/sasa1977/site_encrypt/blob/master/lib/site_encrypt/http_client.ex#L40-L49)
  6. And then the request fails on line 50 where it tries to close the connection (again)

Here is how it looks on my machine:

Screenshot 2024-05-31 at 19 58 33

If I comment out the Mint.HTTP.close line in the after block, everything works as expected, no errors, and the certs are successfully generated.

Based on these experiments, my conclusion is that the additional Mint.HTTP.close is not necessary for the happy path, but I can't explain why no one else is getting this error, only me.


If it helps, I'm using site_encrypt on a phoenix based project with the following versions:

PR for setting up site encrypt on our project for reference: https://github.com/operately/operately/pull/500/files.

sasa1977 commented 1 month ago

I think upgrading Mint to 1.5.1 should fix this problem. See https://github.com/elixir-mint/mint/blob/main/CHANGELOG.md#v151. Can you give it a try?

shiroyasha commented 1 month ago

It works πŸŽ‰

I've run:

mix deps.unlock mint
mix deps.get

After which the server started without a problem and generated a local SSL cert:

✲ NEWDEV ~/code/operately (site-encrypt) ./devenv mix phx.server
14:32:45.297 [info] Running OperatelyWeb.Endpoint with cowboy 2.12.0 at 0.0.0.0:4000 (http)
14:32:45.338 [info] Running OperatelyWeb.Endpoint with cowboy 2.12.0 at 0.0.0.0:4001 (https)
14:32:45.341 [info] Access OperatelyWeb.Endpoint at https://localhost:4001
14:32:45.343 [info] Running local ACME server at port 4002
0.14.54
14:32:45.431 [info] Certificate for localhost is valid until 3023-10-02. Next renewal is scheduled for 3023-09-02.

@sasa1977 what is your suggestion what should we do with the issue, should we close it, or do you want to keep it open?

sasa1977 commented 1 month ago

Since this is a bug in mint 1.5.0, that is easily fixed in the client project by bumping the mint version, I'm closing the issue.