Linux/WSL: engine errors end the engine and reach the client
- The --serve stdin reader reads the descriptor instead of std::cin: glibc's exit() waits for stdin's lock, which getline held while waiting for input, so an engine ending on any error hung in exit() and the server waited forever. - session_init fails when a QSA layer could not pin its KV streaming copy; it used to continue half-built and hit an illegal memory access at the first request (seen under WSL, where the driver pins only about 1 GiB). The message says how much was pinned and what to change. - setup: no KV streaming under WSL (new installs and existing configs). - server: an engine ERR after an SSE stream started is sent as an error event (it was a 400 response written into the open stream: an empty answer), and the request is recorded as "error".
This commit is contained in:
1 parent
fb9b924e5c
commit
6c06571710
6 files changed
+99
-8
No files matched your search
@@ -53,6 +53,10 @@
|
||||
#if defined(_WIN32)
|
||||
#include <windows.h>
|
||||
#include <psapi.h>
|
||||
#include <io.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#include <cerrno>
|
||||
#endif
|
||||
|
||||
#include <cuda_runtime.h>
|
||||
@@ -2445,8 +2449,35 @@ int main(int argc, char** argv) {
|
||||
std::deque<std::string> in_lines;
|
||||
bool in_eof = false;
|
||||
std::thread([&] {
|
||||
std::string l;
|
||||
while (std::getline(std::cin, l)) {
|
||||
// read(2) on the descriptor, not std::cin: glibc's exit() flushes every stdio stream and waits for
|
||||
// stdin's lock, which getline holds while it waits for input - an engine ending on an error (every
|
||||
// std::exit) would hang in exit() on Linux, and the server would wait for it forever
|
||||
std::string l, buf;
|
||||
char chunk[4096];
|
||||
auto getline_fd = [&](std::string& out) -> bool {
|
||||
for (;;) {
|
||||
const size_t nlpos = buf.find('\n');
|
||||
if (nlpos != std::string::npos) {
|
||||
out.assign(buf, 0, nlpos);
|
||||
buf.erase(0, nlpos + 1);
|
||||
return true;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
const int n = _read(0, chunk, (unsigned) sizeof chunk);
|
||||
#else
|
||||
const ssize_t n = ::read(0, chunk, sizeof chunk);
|
||||
if (n < 0 && errno == EINTR) continue;
|
||||
#endif
|
||||
if (n <= 0) {
|
||||
if (buf.empty()) return false;
|
||||
out.swap(buf);
|
||||
buf.clear();
|
||||
return true;
|
||||
}
|
||||
buf.append(chunk, (size_t) n);
|
||||
}
|
||||
};
|
||||
while (getline_fd(l)) {
|
||||
if (!l.empty() && l.back() == '\r') l.pop_back();
|
||||
if (l == "STOP") { stop_req.store(true); continue; }
|
||||
std::lock_guard<std::mutex> lk(in_mu);
|
||||
|
||||
Reference in new issue
Block a user