mirror of
				https://github.com/lightpanda-io/browser.git
				synced 2025-10-29 15:13:28 +00:00 
			
		
		
		
	Merge pull request #987 from lightpanda-io/improve_server_shutdown
	
		
			
	
		
	
	
		
	
		
			Some checks failed
		
		
	
	
		
			
				
	
				e2e-test / zig build release (push) Has been cancelled
				
			
		
			
				
	
				zig-test / zig build dev (push) Has been cancelled
				
			
		
			
				
	
				zig-test / zig test (push) Has been cancelled
				
			
		
			
				
	
				e2e-test / demo-scripts (push) Has been cancelled
				
			
		
			
				
	
				e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
				
			
		
			
				
	
				e2e-test / perf-fmt (push) Has been cancelled
				
			
		
			
				
	
				zig-test / browser fetch (push) Has been cancelled
				
			
		
			
				
	
				zig-test / perf-fmt (push) Has been cancelled
				
			
		
			
				
	
				nightly build / build-linux-x86_64 (push) Has been cancelled
				
			
		
			
				
	
				nightly build / build-linux-aarch64 (push) Has been cancelled
				
			
		
			
				
	
				nightly build / build-macos-aarch64 (push) Has been cancelled
				
			
		
			
				
	
				nightly build / build-macos-x86_64 (push) Has been cancelled
				
			
		
			
				
	
				wpt / web platform tests json output (push) Has been cancelled
				
			
		
			
				
	
				wpt / perf-fmt (push) Has been cancelled
				
			
		
		
	
	
				
					
				
			
		
			Some checks failed
		
		
	
	e2e-test / zig build release (push) Has been cancelled
				
			zig-test / zig build dev (push) Has been cancelled
				
			zig-test / zig test (push) Has been cancelled
				
			e2e-test / demo-scripts (push) Has been cancelled
				
			e2e-test / cdp-and-hyperfine-bench (push) Has been cancelled
				
			e2e-test / perf-fmt (push) Has been cancelled
				
			zig-test / browser fetch (push) Has been cancelled
				
			zig-test / perf-fmt (push) Has been cancelled
				
			nightly build / build-linux-x86_64 (push) Has been cancelled
				
			nightly build / build-linux-aarch64 (push) Has been cancelled
				
			nightly build / build-macos-aarch64 (push) Has been cancelled
				
			nightly build / build-macos-x86_64 (push) Has been cancelled
				
			wpt / web platform tests json output (push) Has been cancelled
				
			wpt / perf-fmt (push) Has been cancelled
				
			Ignore ConnectionClosed error on server shutdown
This commit is contained in:
		| @@ -40,6 +40,7 @@ const MAX_MESSAGE_SIZE = 512 * 1024 + 14 + 140; | ||||
|  | ||||
| pub const Server = struct { | ||||
|     app: *App, | ||||
|     shutdown: bool, | ||||
|     allocator: Allocator, | ||||
|     client: ?posix.socket_t, | ||||
|     listener: ?posix.socket_t, | ||||
| @@ -54,16 +55,20 @@ pub const Server = struct { | ||||
|             .app = app, | ||||
|             .client = null, | ||||
|             .listener = null, | ||||
|             .shutdown = false, | ||||
|             .allocator = allocator, | ||||
|             .json_version_response = json_version_response, | ||||
|         }; | ||||
|     } | ||||
|  | ||||
|     pub fn deinit(self: *Server) void { | ||||
|         self.allocator.free(self.json_version_response); | ||||
|         self.shutdown = true; | ||||
|         if (self.listener) |listener| { | ||||
|             posix.close(listener); | ||||
|         } | ||||
|         // *if* server.run is running, we should really wait for it to return | ||||
|         // before existing from here. | ||||
|         self.allocator.free(self.json_version_response); | ||||
|     } | ||||
|  | ||||
|     pub fn run(self: *Server, address: net.Address, timeout_ms: i32) !void { | ||||
| @@ -82,6 +87,9 @@ pub const Server = struct { | ||||
|         log.info(.app, "server running", .{ .address = address }); | ||||
|         while (true) { | ||||
|             const socket = posix.accept(listener, null, null, posix.SOCK.NONBLOCK) catch |err| { | ||||
|                 if (self.shutdown) { | ||||
|                     return; | ||||
|                 } | ||||
|                 log.err(.app, "CDP accept", .{ .err = err }); | ||||
|                 std.Thread.sleep(std.time.ns_per_s); | ||||
|                 continue; | ||||
|   | ||||
		Reference in New Issue
	
	Block a user
	 Karl Seguin
					Karl Seguin