Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Double connection close on exception. #76

Closed
qnikst opened this issue Dec 22, 2020 · 0 comments
Closed

Double connection close on exception. #76

qnikst opened this issue Dec 22, 2020 · 0 comments
Assignees
Labels
Milestone

Comments

@qnikst
Copy link
Owner

qnikst commented Dec 22, 2020

Currently in case of the protocol error we close connection and throw an exception afterwards:

| otherwise -> do
bsClose (bsstream conn)
fail $ "cannot execute command " ++ show cmd ++
", " ++ prettyExpected expectedReplies ++
", " ++ prettyReceived code msg

It means that when we exit from doSMTP* we close connection again:

bracket (connectSMTPPort host port) closeSMTP

-- | close the connection. This function send the QUIT method, so you
-- do not have to QUIT method explicitly.
closeSMTP :: SMTPConnection -> IO ()
closeSMTP (SMTPC conn _) = bsClose conn
{-
I must be being stupid here
I can't seem to be able to catch the exception arising from the
connection already being closed this would be the correct way to do it
but instead we're being naughty above by just closes the connection
without first sending QUIT
closeSMTP c@(SMTPC conn _) =
do sendCommand c QUIT
bsClose conn `catch` \(_ :: IOException) -> return ()
-}

Even we handle exception here, it's not safe to close the same handle twice as it could be allocated for a completely different connection.

@qnikst qnikst added the bug label Dec 22, 2020
@qnikst qnikst added this to the 0.6 milestone Dec 22, 2020
@qnikst qnikst self-assigned this Dec 22, 2020
@qnikst qnikst closed this as completed in a64c17f Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant