Skip to content

Commit d81377b

Browse files
authored
Merge pull request #1007 from lightpanda-io/timeout_limit
Limit serve timeout to 1 week
2 parents 7c6870f + da128f5 commit d81377b

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

src/main.zig

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,9 @@ fn run(alloc: Allocator) !void {
137137
const server = &_server.?;
138138
defer server.deinit();
139139

140-
server.run(address, opts.timeout * 1000) catch |err| {
140+
// max timeout of 1 week.
141+
const timeout = if (opts.timeout > 604_800) 604_800_000 else @as(i32, opts.timeout) * 1000;
142+
server.run(address, timeout) catch |err| {
141143
log.fatal(.app, "server run error", .{ .err = err });
142144
return err;
143145
};
@@ -268,7 +270,7 @@ const Command = struct {
268270
const Serve = struct {
269271
host: []const u8,
270272
port: u16,
271-
timeout: u16,
273+
timeout: u31,
272274
common: Common,
273275
};
274276

@@ -369,7 +371,7 @@ const Command = struct {
369371
\\ Defaults to 9222
370372
\\
371373
\\--timeout Inactivity timeout in seconds before disconnecting clients
372-
\\ Defaults to 10 (seconds)
374+
\\ Defaults to 10 (seconds). Limited to 604800 (1 week).
373375
\\
374376
++ common_options ++
375377
\\
@@ -465,7 +467,7 @@ fn parseServeArgs(
465467
) !Command.Serve {
466468
var host: []const u8 = "127.0.0.1";
467469
var port: u16 = 9222;
468-
var timeout: u16 = 10;
470+
var timeout: u31 = 10;
469471
var common: Command.Common = .{};
470472

471473
while (args.next()) |opt| {
@@ -497,7 +499,7 @@ fn parseServeArgs(
497499
return error.InvalidArgument;
498500
};
499501

500-
timeout = std.fmt.parseInt(u16, str, 10) catch |err| {
502+
timeout = std.fmt.parseInt(u31, str, 10) catch |err| {
501503
log.fatal(.app, "invalid argument value", .{ .arg = "--timeout", .err = err });
502504
return error.InvalidArgument;
503505
};

0 commit comments

Comments
 (0)