Skip to content

Return error in case of runner crash #69

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft

Conversation

p1-0tr
Copy link
Member

@p1-0tr p1-0tr commented Jun 5, 2025

In case the runner crashes it would be nice to return an error to the
user. So, add an error handler on the proxy and use it to try to figure
out if the runner crashed and format the response error accordingly.

Based on: #68

p1-0tr added 2 commits June 5, 2025 13:16
In case a runner becomes defunct, e.g. as a result of a backend crash it
would be neat to be able to reload it. So, if the loader finds runner,
have it check if the runner is still alive, and create a new one if the
runner is defunct.

Signed-off-by: Piotr Stankiewicz <[email protected]>
In case the runner crashes it would be nice to return an error to the
user. So, add an error handler on the proxy and use it to try to figure
out if the runner crashed and format the response error accordingly.

Signed-off-by: Piotr Stankiewicz <[email protected]>
@p1-0tr p1-0tr requested review from xenoscopic and doringeman June 5, 2025 12:05
return l.slots[existing], nil
select {
case <-l.slots[existing].done:
l.log.Warnf("Will reload defunct %s runner for %s. Runner error: %s.", backendName, model,

Check failure

Code scanning / CodeQL

Log entries created from user input High

This log entry depends on a
user-provided value
.

Copilot Autofix

AI 3 days ago

To fix the issue, the user-provided model value should be sanitized before being logged. Since the log entries are plain text, we can remove newline characters (\n and \r) from the model string to prevent log forgery. This can be achieved using the strings.ReplaceAll function.

The sanitization should be applied in the load function in loader.go before the model value is used in the Warnf log statement. This ensures that any malicious input is neutralized before being logged.


Suggested changeset 1
pkg/inference/scheduling/loader.go

Autofix patch

Autofix patch
Run the following command in your local git repository to apply this patch
cat << 'EOF' | git apply
diff --git a/pkg/inference/scheduling/loader.go b/pkg/inference/scheduling/loader.go
--- a/pkg/inference/scheduling/loader.go
+++ b/pkg/inference/scheduling/loader.go
@@ -12,2 +12,3 @@
 	"github.com/docker/model-runner/pkg/logging"
+	"strings"
 )
@@ -376,3 +377,5 @@
 			case <-l.slots[existing].done:
-				l.log.Warnf("Will reload defunct %s runner for %s. Runner error: %s.", backendName, model,
+				sanitizedModel := strings.ReplaceAll(model, "\n", "")
+				sanitizedModel = strings.ReplaceAll(sanitizedModel, "\r", "")
+				l.log.Warnf("Will reload defunct %s runner for %s. Runner error: %s.", backendName, sanitizedModel,
 					l.slots[existing].err)
EOF
@@ -12,2 +12,3 @@
"github.com/docker/model-runner/pkg/logging"
"strings"
)
@@ -376,3 +377,5 @@
case <-l.slots[existing].done:
l.log.Warnf("Will reload defunct %s runner for %s. Runner error: %s.", backendName, model,
sanitizedModel := strings.ReplaceAll(model, "\n", "")
sanitizedModel = strings.ReplaceAll(sanitizedModel, "\r", "")
l.log.Warnf("Will reload defunct %s runner for %s. Runner error: %s.", backendName, sanitizedModel,
l.slots[existing].err)
Copilot is powered by AI and may make mistakes. Always verify output.
@@ -134,6 +135,28 @@ func run(
proxyLog: proxyLog,
}

proxy.ErrorHandler = func(w http.ResponseWriter, req *http.Request, err error) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since this is going to be sent back to OpenAI clients, I would try to structure the error responses in a format they can parse. Documentation is a little sparse, but Google says the error format looks like:

{
  "error": {
    "message": "Invalid 'messages[1].content': string too long. Expected a string with maximum length 1048576, but got a string with length 1540820 instead.",
    "type": "invalid_request_error",
    "param": "messages[1].content",
    "code": "string_above_max_length"
  }
}

The only docs I can find for the API are https://platform.openai.com/docs/api-reference/responses-streaming/error

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants