Skip to content
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

Extract the connection monitor from the connection manager #1173

Merged
merged 1 commit into from
May 13, 2021

Conversation

glbrntt
Copy link
Collaborator

@glbrntt glbrntt commented May 11, 2021

Motivation:

The connection monitor allows users to register a delegate for changes
in connectivity state as well as access the current state. Because the
user code may call out it is executed on a DispatchQueue (rather than
the connection's EventLoop).

However, there are cases within gRPC where state change notifications
on the event loop are very useful (such as in a pool of connection
managers all running on the same event loop).

Moreover, it's not necessary for the connection manager to hold the
connection monitor, it just needs a way to inform it about any changes
so that it can call any user provided delegates.

Modifications:

  • Extract the connectivity monitor from the connection manager
  • Allow on-event-loop callbacks to be passed to the connection manager
    for connection state changes and for certain HTTP/2 events (stream
    closed and receiving max concurrent streams settings). While not
    strictly necessary for this change they will be helpful down the line.
  • Update a bunch of tests.

Result:

The connection manager no longer holds a connection monitor and may
execute state change callbacks on the event loop.

@glbrntt glbrntt added the 🔨 semver/patch No public API change. label May 11, 2021
@glbrntt glbrntt requested a review from Lukasa May 11, 2021 08:25
@glbrntt glbrntt force-pushed the gb-connection-manager-delegate branch 3 times, most recently from 66ec32e to afdc96c Compare May 11, 2021 16:26
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

One brief note inline.

Sources/GRPC/ConnectionManager.swift Outdated Show resolved Hide resolved
Motivation:

The connection monitor allows users to register a delegate for changes
in connectivity state as well as access the current state. Because the
user code may call out it is executed on a `DispatchQueue` (rather than
the connection's `EventLoop`).

However, there are cases within gRPC where state change notifications
on the event loop are very useful (such as in a pool of connection
managers all running on the same event loop).

Moreover, it's not necessary for the connection manager to hold the
connection monitor, it just needs a way to inform it about any changes
so that it can call any user provided delegates.

Modifications:

- Extract the connectivity monitor from the connection manager
- Allow on-event-loop callbacks to be passed to the connection manager
  for connection state changes and for certain HTTP/2 events (stream
  closed and receiving max concurrent streams settings). While not
  strictly necessary for this change they will be helpful down the line.
- Update a bunch of tests.

Result:

The connection manager no longer holds a connection monitor and may
execute state change callbacks on the event loop.
@glbrntt glbrntt force-pushed the gb-connection-manager-delegate branch from afdc96c to 72b4b61 Compare May 12, 2021 15:29
@glbrntt glbrntt requested a review from Lukasa May 12, 2021 15:30
Copy link
Collaborator

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Nice, LGTM.

Copy link
Collaborator

@fabianfett fabianfett left a comment

Choose a reason for hiding this comment

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

Cool. LGTM!

@@ -1025,6 +1012,106 @@ extension ConnectionManagerTests {
XCTAssertNoThrow(try shutdown.wait())
}
}

func testHTTP2Delegates() throws {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nit: do we need the throws here?

@glbrntt glbrntt merged commit 71b3380 into grpc:main May 13, 2021
@glbrntt glbrntt deleted the gb-connection-manager-delegate branch May 13, 2021 10:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants