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

Add GRPC keepalives back #214

Merged
merged 4 commits into from
May 2, 2024
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
5 changes: 5 additions & 0 deletions .changeset/weak-walls-cover.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@xmtp/grpc-api-client": patch
---

Adjust GRPC keepalive settings
16 changes: 10 additions & 6 deletions packages/grpc-api-client/src/GrpcApiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,21 @@ import {
} from "./gen/message_api/v1/message_api.js"

const API_URLS: { [k: string]: string } = {
dev: "dev.xmtp.network:5556",
production: "production.xmtp.network:5556",
dev: "grpc.dev.xmtp.network:443",
production: "grpc.production.xmtp.network:443",
local: "localhost:5556",
}

const SLEEP_TIME = 1000
const MAX_RETRIES = 4

const clientOptions = {
"grpc.keepalive_timeout_ms": 1000 * 10, // 10 seconds
"grpc.keepalive_time_ms": 1000 * 30, // 30 seconds
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure I understand the relationship between these and the 15 second timeout on the nodes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

15 second on the node is the floor that the node will allow before it gets angry. We don't need 15 seconds on servers where we have pretty reliable internet. It's helpful on the phone where the keepalives can help detect connection drops.

Arguably even 30 seconds is needlessly low. The reports of connection failures happen around the 5 minute mark.

"grpc.enable_retries": 1,
"grpc.keepalive_permit_without_calls": 0,
} as const

export default class GrpcApiClient implements ApiClient {
grpcClient: MessageApiClient
private authCache?: AuthCache
Expand All @@ -58,10 +65,7 @@ export default class GrpcApiClient implements ApiClient {
this.grpcClient = new MessageApiClient(
new GrpcTransport({
host: apiUrl,
clientOptions: {
"grpc.keepalive_time_ms": 1000 * 60 * 5, // 5 minutes
"grpc.enable_retries": 1,
},
clientOptions,
channelCredentials: isSecure
? credentials.createSsl()
: credentials.createInsecure(),
Expand Down
Loading