Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions lib/async/http/protocol/http2/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,7 @@ def accept_stream(stream_id)

# Close the server connection and stop accepting requests.
def close(error = nil)
if @requests
# Stop the request loop:
@requests.enqueue(nil)
@requests = nil
end
@requests.close

super
end
Expand All @@ -57,7 +53,7 @@ def each(task: Task.current)
task.annotate("Reading #{version} requests for #{self.class}.")

# It's possible the connection has died before we get here...
@requests&.async do |task, request|
@requests.async do |task, request|
task.annotate("Incoming request: #{request.method} #{request.path.inspect}.")

response = nil
Expand Down
31 changes: 31 additions & 0 deletions test/async/http/protocol/http2/server.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2026, by Samuel Williams.

require "async/http/protocol/http2"
require "sus/fixtures/async/scheduler_context"
require "socket"

describe Async::HTTP::Protocol::HTTP2::Server do
include Sus::Fixtures::Async::SchedulerContext

let(:sockets) {Socket.pair(Socket::PF_UNIX, Socket::SOCK_STREAM)}
let(:stream) {IO::Stream(sockets.first)}
let(:server) {subject.new(stream)}

it "closes the request queue" do
request = Object.new
server.requests.enqueue(request)

server.close

expect(server.requests).to be(:closed?)
expect(server.requests.dequeue).to be == request
expect(server.requests.dequeue).to be_nil

expect do
server.requests.enqueue(Object.new)
end.to raise_exception(Async::Queue::ClosedError)
end
end
Loading