Merge pull request #9798 from edolstra/remote-store-eof

Print a more helpful message if the daemon crashes

(cherry picked from commit 32706b14a7531c2c21b9f96da083a540a0031ec4)
Change-Id: Ief7c465bca7666e2b7e7c9d1dd0c01c5f9014146
This commit is contained in:
eldritch horrors 2024-03-04 08:12:15 +01:00
parent 5dd872363a
commit 68f148ed45
3 changed files with 5 additions and 3 deletions

View file

@ -65,6 +65,7 @@ void RemoteStore::initConnection(Connection & conn)
{ {
/* Send the magic greeting, check for the reply. */ /* Send the magic greeting, check for the reply. */
try { try {
conn.from.endOfFileError = "Nix daemon disconnected unexpectedly (maybe it crashed?)";
conn.to << WORKER_MAGIC_1; conn.to << WORKER_MAGIC_1;
conn.to.flush(); conn.to.flush();
StringSink saved; StringSink saved;

View file

@ -128,7 +128,7 @@ size_t FdSource::readUnbuffered(char * data, size_t len)
n = ::read(fd, data, len); n = ::read(fd, data, len);
} while (n == -1 && errno == EINTR); } while (n == -1 && errno == EINTR);
if (n == -1) { _good = false; throw SysError("reading from file"); } if (n == -1) { _good = false; throw SysError("reading from file"); }
if (n == 0) { _good = false; throw EndOfFile("unexpected end-of-file"); } if (n == 0) { _good = false; throw EndOfFile(std::string(*endOfFileError)); }
read += n; read += n;
return n; return n;
} }

View file

@ -151,6 +151,7 @@ struct FdSource : BufferedSource
{ {
int fd; int fd;
size_t read = 0; size_t read = 0;
BackedStringView endOfFileError{"unexpected end-of-file"};
FdSource() : fd(-1) { } FdSource() : fd(-1) { }
FdSource(int fd) : fd(fd) { } FdSource(int fd) : fd(fd) { }