Skip to content

Conversation

@mabiede
Copy link
Contributor

@mabiede mabiede commented Jun 12, 2025

Issue

Behavior: The mailer service is expected to send a lot of emails, and it does so successfully. However, it leaves many connections in the CLOSE_WAIT state, which can lead to resource exhaustion (locally with mailtrap, it stopped around 1010).

... a lot more of these lines ...
test_mail 57572 57574 test_mail opam  777u     IPv4            5117875      0t0     TCP 2ac8aaaf97d7:35134->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  778u     IPv4            5117876      0t0     TCP 2ac8aaaf97d7:35150->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  779u     IPv4            5125718      0t0     TCP 2ac8aaaf97d7:35154->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  780u     IPv4            5125719      0t0     TCP 2ac8aaaf97d7:35164->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  781u     IPv4            5128011      0t0     TCP 2ac8aaaf97d7:35174->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  782u     IPv4            5117877      0t0     TCP 2ac8aaaf97d7:35186->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  783u     IPv4            5117878      0t0     TCP 2ac8aaaf97d7:35188->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  784u     IPv4            5128012      0t0     TCP 2ac8aaaf97d7:35202->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  785u     IPv4            5130581      0t0     TCP 2ac8aaaf97d7:35206->mailtrap-letters.letters_devcontainer_default:1025 (CLOSE_WAIT)
test_mail 57572 57574 test_mail opam  786u     IPv4            5132789      0t0     TCP 2ac8aaaf97d7:35220->mailtrap-letters.letters_devcontainer_default:1025 (ESTABLISHED)

Fix

  • See changes of file: lib/sendmail_handler.ml

The following lines show the output after adjustments. No connections left with CLOSE_WAIT state. Always the same amount of connections (tested locally with 10000 mails)

test_mail 58384                 opam    1w      REG              254,1        0 2303086 ./service-test/_build/_tests/GPHM7WVI/use mailtrapU+002C test a lot of emails.000.output
test_mail 58384                 opam    2w      REG              254,1        0 2303086 ./service-test/_build/_tests/GPHM7WVI/use mailtrapU+002C test a lot of emails.000.output
test_mail 58384                 opam    4w      REG              254,1        0 2303086 ./service-test/_build/_tests/GPHM7WVI/use mailtrapU+002C test a lot of emails.000.output
test_mail 58384 58386 test_mail opam    1w      REG              254,1        0 2303086 ./service-test/_build/_tests/GPHM7WVI/use mailtrapU+002C test a lot of emails.000.output
test_mail 58384 58386 test_mail opam    2w      REG              254,1        0 2303086 ./service-test/_build/_tests/GPHM7WVI/use mailtrapU+002C test a lot of emails.000.output
test_mail 58384 58386 test_mail opam    4w      REG              254,1        0 2303086 ./service-test/_build/_tests/GPHM7WVI/use mailtrapU+002C test a lot of emails.000.output

The test is pushed to the following branch, as it's not designed to run in CI I'd keep it there: https://github.com/mabiede/letters/blob/dev/mailspam-testcase/service-test/test_mailspam.ml#L22

Additional

I did maintenance on the devcontainer setup and simplified it.

@mabiede
Copy link
Contributor Author

mabiede commented Jun 12, 2025

@aronerben @joseferben @mikonieminen we'd appreciate a merge and bug release for this PR. Thanks

@mabiede
Copy link
Contributor Author

mabiede commented Jul 24, 2025

@aronerben @joseferben @mikonieminen any update on this?

@mabiede
Copy link
Contributor Author

mabiede commented Aug 11, 2025

@joseferben @aronerben ping

@aronerben
Copy link
Contributor

@mabiede Hello, sorry, I'm too far away from the matter to give this a proper review. From what I can remember though, the PR seems good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants