Skip to content

Commit

Permalink
Fix error message when one side of unix sockets is closed for writing.
Browse files Browse the repository at this point in the history
When one end of the connection is closed, write for unix sockets returns
connection refused error in Linux. Make the gVisor behavior the same as Linux.

PiperOrigin-RevId: 631949102
  • Loading branch information
nybidari authored and gvisor-bot committed May 9, 2024
1 parent a3b19da commit ad86743
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 6 additions & 0 deletions pkg/sentry/socket/unix/unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,12 @@ func (s *Socket) Write(ctx context.Context, src usermem.IOSequence, opts vfs.Wri
if w.Notify != nil {
w.Notify()
}
if _, skType, _ := s.Type(); skType == linux.SOCK_DGRAM {
if err != nil && err.Error() == linuxerr.EPIPE.Error() {
log.Infof("HERE....")
return n, linuxerr.ECONNREFUSED
}
}
return n, err

}
Expand Down
4 changes: 0 additions & 4 deletions test/syscalls/linux/socket_unix_dgram.cc
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@ namespace testing {
namespace {

TEST_P(DgramUnixSocketPairTest, WriteOneSideClosed) {
// FIXME(b/35925052): gVisor datagram sockets return EPIPE instead of
// ECONNREFUSED.
SKIP_IF(IsRunningOnGvisor());

auto sockets = ASSERT_NO_ERRNO_AND_VALUE(NewSocketPair());
ASSERT_THAT(close(sockets->release_first_fd()), SyscallSucceeds());
constexpr char kStr[] = "abc";
Expand Down

0 comments on commit ad86743

Please sign in to comment.