From c0b3f3b78aff46e56aff9b9c091b6f04572107f1 Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 29 Feb 2020 08:22:34 +0000 Subject: better error messages --- internal/server/handlers/controlhandler.go | 2 +- internal/server/handlers/serverhandler.go | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) (limited to 'internal/server') diff --git a/internal/server/handlers/controlhandler.go b/internal/server/handlers/controlhandler.go index a33a78b..daa9835 100644 --- a/internal/server/handlers/controlhandler.go +++ b/internal/server/handlers/controlhandler.go @@ -87,6 +87,6 @@ func (h *ControlHandler) handleCommand(ctx context.Context, command string) { case "debug": h.serverMessages <- logger.Debug(h.user, "Receiving debug command", command, s) default: - h.serverMessages <- logger.Warn(h.user, "Received unknown command", command, s) + h.serverMessages <- logger.Warn(h.user, "Received unknown control command", command, s) } } diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go index 819cddd..ba3a78e 100644 --- a/internal/server/handlers/serverhandler.go +++ b/internal/server/handlers/serverhandler.go @@ -233,7 +233,7 @@ func (h *ServerHandler) handleControlCommand(argc int, args []string) { case "debug": h.send(h.serverMessages, logger.Debug(h.user, "Receiving debug command", argc, args)) default: - logger.Warn(h.user, "Received unknown command", argc, args) + logger.Warn(h.user, "Received unknown control command", argc, args) } } @@ -248,7 +248,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args [] } splitted := strings.Split(args[0], ":") - command := splitted[0] + commandName := splitted[0] // TODO: Refactor: Create an "options" clase, combine makeOptions and readOptions there. options, err := readOptions(splitted[1:]) @@ -258,7 +258,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args [] return } - switch command { + switch commandName { case "grep", "cat": command := newReadCommand(h, omode.CatClient) h.incrementActiveCommands() @@ -369,7 +369,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args [] finished() default: - h.sendServerMessage(logger.Error(h.user, "Received unknown command", argc, args)) + h.sendServerMessage(logger.Error(h.user, "Received unknown user command", commandName, argc, args, options)) finished() } } -- cgit v1.2.3 From 47c27356c3efd72c321dbea4d8dd25085718a47c Mon Sep 17 00:00:00 2001 From: Paul Buetow Date: Sat, 29 Feb 2020 09:07:56 +0000 Subject: background jobs make use of the timeout specified by the client too --- internal/server/handlers/serverhandler.go | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) (limited to 'internal/server') diff --git a/internal/server/handlers/serverhandler.go b/internal/server/handlers/serverhandler.go index ba3a78e..007c489 100644 --- a/internal/server/handlers/serverhandler.go +++ b/internal/server/handlers/serverhandler.go @@ -176,11 +176,11 @@ func (h *ServerHandler) handleCommand(ctx context.Context, commandStr string) { <-commandCtx.Done() cancel() }() - h.handleUserCommand(commandCtx, argc, args) + h.handleUserCommand(commandCtx, argc, args, timeout) return } - h.handleUserCommand(ctx, argc, args) + h.handleUserCommand(ctx, argc, args, timeout) } func (h *ServerHandler) handleProtocolVersion(args []string) ([]string, int, error) { @@ -237,7 +237,7 @@ func (h *ServerHandler) handleControlCommand(argc int, args []string) { } } -func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args []string) { +func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args []string, timeout time.Duration) { logger.Debug(h.user, "handleUserCommand", argc, args) h.incrementActiveCommands() @@ -296,7 +296,7 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args [] jobName, _ := options["jobName"] logger.Debug(h.user, "run", options) - if val, ok := options["background"]; ok && val == "cancel" { + if val, ok := options["background"]; ok && (val == "cancel" || val == "stop") { if err := h.background.Cancel(h.user.Name, jobName); err != nil { h.sendServerMessage(logger.Error(h.user, err, jobName, args)) } else { @@ -330,7 +330,13 @@ func (h *ServerHandler) handleUserCommand(ctx context.Context, argc int, args [] wg.Add(1) if background { - commandCtx, cancel := context.WithCancel(h.serverCtx) + if timeout == 0 { + // Set default background timeout. + timeout = time.Hour * 1 + } + // Use a new context based on the server context, so that background job does not get + // terminated when handler/SSH connection terminates. + commandCtx, cancel := context.WithTimeout(h.serverCtx, timeout) // TODO: For background jobs dont attempt to send data to dtail client as there might be no SSH connection if err := h.background.Add(h.user.Name, jobName, cancel, &wg); err != nil { -- cgit v1.2.3