[
https://issues.apache.org/jira/browse/TS-4522?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15328008#comment-15328008
]
ASF GitHub Bot commented on TS-4522:
------------------------------------
Github user jpeach commented on the issue:
https://github.com/apache/trafficserver/pull/701
AFAICT we would get ``EPIPE`` when we write to a socket that has been
closed. This would be an error because there is unwritten data that we can't
write. We would get ``ECONNRESET`` reading from a socket that is closed. The
other side closed the socket but we don't know whether that was premature or
not (yet). Most places that I saw treated ``VC_EVENT_ERROR`` and
``VC_EVENT_EOS`` similarly apart from logging.
By the same logic, I agree that handling ``ECONNRESET`` specially in
``write_to_net_io`` looks odd and could be a bug. Maybe the right change is to
remove the ``ECONNRESET`` check in ``write_to_net_io``. Also in this code path,
the return from ``UnixNetVConnection::load_buffer_and_write`` should never be 0
because we never try to write 0 bytes.
So consider:
```C
diff --git a/iocore/net/UnixNetVConnection.cc
b/iocore/net/UnixNetVConnection.cc
index b52985c..bc9764d 100644
--- a/iocore/net/UnixNetVConnection.cc
+++ b/iocore/net/UnixNetVConnection.cc
@@ -535,11 +535,9 @@ write_to_net_io(NetHandler *nh, UnixNetVConnection
*vc, EThread *thread)
}
return;
}
- if (!r || r == -ECONNRESET) {
- vc->write.triggered = 0;
- write_signal_done(VC_EVENT_EOS, nh, vc);
- return;
- }
+ // A write of 0 makes no sense since we tried to write more than 0.
Either
+ // we wrote something or we got an error.
+ ink_assert(r < 0);
vc->write.triggered = 0;
write_signal_error(nh, vc, (int)-total_written);
return;
```
> did not check EPIPE on write_to_net_io
> --------------------------------------
>
> Key: TS-4522
> URL: https://issues.apache.org/jira/browse/TS-4522
> Project: Traffic Server
> Issue Type: Bug
> Components: Core, Network
> Reporter: Oknet Xu
> Assignee: Oknet Xu
> Fix For: 7.0.0
>
>
> On a closed socket fd:
> read(socketfd) return 0
> write(socketfd) return EPIPE
> In the write_to_net_io, we check the return value of write() with the same
> way to read().
> {code}
> if (!r || r == -ECONNRESET) {
> {code}
> The bug makes no VC_EVENT_EOS callbacked while write_to_net_io, but
> VC_EVENT_ERROR instead.
> full code here:
> {code}
> int64_t r = vc->load_buffer_and_write(towrite, buf, total_written, needs);
> if (total_written > 0) {
> NET_SUM_DYN_STAT(net_write_bytes_stat, total_written);
> s->vio.ndone += total_written;
> }
> // check for errors
> if (r <= 0) { // if the socket was not ready,add to WaitList
> if (r == -EAGAIN || r == -ENOTCONN) {
> NET_INCREMENT_DYN_STAT(net_calls_to_write_nodata_stat);
> if ((needs & EVENTIO_WRITE) == EVENTIO_WRITE) {
> vc->write.triggered = 0;
> nh->write_ready_list.remove(vc);
> write_reschedule(nh, vc);
> }
> if ((needs & EVENTIO_READ) == EVENTIO_READ) {
> vc->read.triggered = 0;
> nh->read_ready_list.remove(vc);
> read_reschedule(nh, vc);
> }
> return;
> }
> if (!r || r == -ECONNRESET) {
> vc->write.triggered = 0;
> write_signal_done(VC_EVENT_EOS, nh, vc);
> return;
> }
> vc->write.triggered = 0;
> write_signal_error(nh, vc, (int)-total_written);
> return;
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)