Skip to content

Uncaughtable error when host rejects the connection #2

@edubart

Description

@edubart

If you try to send an email and hosts rejects the connection with RST, it generates the following error:

2018/08/17 09:24:47 [error] 32027#0: *19 connect() failed (111: Connection refused), context: ngx.timer
2018/08/17 09:24:47 [error] 32027#0: *19 attempt to send data on a closed socket: u:00000000400214C8, c:0000000000000000, ft:0 eof:0, context: ngx.timer

This error is not caughtable even with pcall or handling error status, example:

First on the smtp host we force to reject doing:

iptables -I INPUT -s <myip> -p tcp --dport 587 -j REJECT --reject-with tcp-reset

Then we try to send an email:

local ok, err = pcall(function()
  local mailer = assert(resty_mail.new(config.mailer))
  assert(mailer:send({
    from = 'test@test.com',
    to = 'test@test.com',
    subject = 'test',
    text = 'test',
  }))
end)
print('result', ok, err)

This outputs:

2018/08/17 09:24:47 [error] 32027#0: *19 connect() failed (111: Connection refused), context: ngx.timer
2018/08/17 09:24:47 [error] 32027#0: *19 attempt to send data on a closed socket: u:00000000400214C8, c:0000000000000000, ft:0 eof:0, context: ngx.timer
2018/08/17 09:24:52 [notice] 32027#0: *19 result    false    connect failure: connection refused, context: ngx.timer

What we wanted is just the last message because on the above code we intended to handle all errors.

The problem is even after a connection failure lua-resty-mail try to send data.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions