kgio RubyGem user+dev discussion/patches/pulls/bugs/help
 help / color / mirror / code / Atom feed
* kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)"
@ 2012-04-09 23:00 Iñaki Baz Castillo
  2012-04-09 23:22 ` Iñaki Baz Castillo
  2012-04-10 20:15 ` Eric Wong
  0 siblings, 2 replies; 4+ messages in thread
From: Iñaki Baz Castillo @ 2012-04-09 23:00 UTC (permalink / raw)
  To: kgio

Hi, I've realized that in certain cases Kgio::TCPSocket#kgio_trywrite
raises a "Broken pipe - send (Errno::EPIPE)" exception.

In my test case, I use Kgio::TCPSocket within EventMachine (using
EM.watch and so).

- Open the connection (*persistent* connection).

- Send a SIP request (like HTTP) to my custom server which replies a
SIP response.

- When "any data" is received (maybe not the entire SIP response since
I use kgio_tryread(40) for testing purposes) I send a *new* SIP
request.

- This means that, at some point, I send much more data than the received one.

- If when reading the received data with kgio_tryread(XXX), XXX is
equal or greater than the SIP response size, then there is no issue
and it works forever.

- But if XXX is less that the SIP response size, then at some point I
get an exception when calling to  Kgio::TCPSocket#kgio_trywrite:

    "Broken pipe - send (Errno::EPIPE)"


I assume this is since the TCP buffer is filled due to the above
"strange" test case. So I wonder, shouldn't kgio_trywrite return
:error_epipe? :)

-- 
Iñaki Baz Castillo
<ibc@aliax.net>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)"
  2012-04-09 23:00 kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)" Iñaki Baz Castillo
@ 2012-04-09 23:22 ` Iñaki Baz Castillo
  2012-04-10 20:15 ` Eric Wong
  1 sibling, 0 replies; 4+ messages in thread
From: Iñaki Baz Castillo @ 2012-04-09 23:22 UTC (permalink / raw)
  To: kgio

In the same experiment, when the previous problem does not occur (due
to the big enough XXX value in kgio_tryred(XXX)), if the server
terminates the connection then kgio_tryred(XXX) raises
Errno::ECONNRESET. So wouldn't be better :error_econnreset?

-- 
Iñaki Baz Castillo
<ibc@aliax.net>

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)"
  2012-04-09 23:00 kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)" Iñaki Baz Castillo
  2012-04-09 23:22 ` Iñaki Baz Castillo
@ 2012-04-10 20:15 ` Eric Wong
  2012-04-10 20:56   ` Iñaki Baz Castillo
  1 sibling, 1 reply; 4+ messages in thread
From: Eric Wong @ 2012-04-10 20:15 UTC (permalink / raw)
  To: kgio

Iñaki Baz Castillo <ibc@aliax.net> wrote:
> Hi, I've realized that in certain cases Kgio::TCPSocket#kgio_trywrite
> raises a "Broken pipe - send (Errno::EPIPE)" exception.

EPIPE means the reader got closed or died somehow.  EPIPE is uncommon
in normal use, but it is fatal and not possible to recover from (unlike
EAGAIN).

kgio already skips the expensive backtrace generation for
EPIPE/ECONNRESET since there's nothing the programmer can do about it in
non-buggy code, though.  (An attacker can trigger EPIPE/ECONNRESET,
though, so this adds a _small_ amount of DoS protection)

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)"
  2012-04-10 20:15 ` Eric Wong
@ 2012-04-10 20:56   ` Iñaki Baz Castillo
  0 siblings, 0 replies; 4+ messages in thread
From: Iñaki Baz Castillo @ 2012-04-10 20:56 UTC (permalink / raw)
  To: kgio

2012/4/10 Eric Wong <normalperson@yhbt.net>:
> Iñaki Baz Castillo <ibc@aliax.net> wrote:
>> Hi, I've realized that in certain cases Kgio::TCPSocket#kgio_trywrite
>> raises a "Broken pipe - send (Errno::EPIPE)" exception.
>
> EPIPE means the reader got closed or died somehow.  EPIPE is uncommon
> in normal use, but it is fatal and not possible to recover from (unlike
> EAGAIN).

Sure, what I mean is that kgio_trywrite could return :error_epipe so I
would terminate the socket and so :)



> kgio already skips the expensive backtrace generation for
> EPIPE/ECONNRESET since there's nothing the programmer can do about it in
> non-buggy code, though.  (An attacker can trigger EPIPE/ECONNRESET,
> though, so this adds a _small_ amount of DoS protection)

Opss:

  rescue => e
    puts "#{e.class}: #{e.message}"
    puts "backtrace: #{e.backtrace.inspect}"

Result:

  Errno::ECONNRESET: Connection reset by peer - recv> -
  backtrace: ""


Good :)

-- 
Iñaki Baz Castillo
<ibc@aliax.net>

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2012-04-10 20:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-04-09 23:00 kgio_trywrite raises "Broken pipe - send (Errno::EPIPE)" Iñaki Baz Castillo
2012-04-09 23:22 ` Iñaki Baz Castillo
2012-04-10 20:15 ` Eric Wong
2012-04-10 20:56   ` Iñaki Baz Castillo

Code repositories for project(s) associated with this public inbox

	https://yhbt.net/kgio.git/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).