Skip to content

Commit

Permalink
Merge branch 'master' into addAutherror
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Jul 13, 2023
2 parents 9f64d9a + c7e07a0 commit 9e65565
Show file tree
Hide file tree
Showing 8 changed files with 17 additions and 13 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/dart.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
matrix:
sdk: [3.0.0, dev]
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f
with:
sdk: ${{ matrix.sdk }}
Expand Down Expand Up @@ -70,7 +70,7 @@ jobs:
- os: macos-latest
platform: chrome
steps:
- uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab
- uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9
- uses: dart-lang/setup-dart@d6a63dab3335f427404425de0fbfed4686d93c4f
with:
sdk: ${{ matrix.sdk }}
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Add const constructor to `GrpcError` fixing #606.
* Make `GrpcError` non-final to allow implementations.
* Only send keepalive pings on open connections.
* Fix interop tests.

## 3.2.2

Expand Down
2 changes: 2 additions & 0 deletions lib/grpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export 'src/auth/auth_io.dart'
ServiceAccountAuthenticator;
export 'src/client/call.dart' show ClientCall;
export 'src/client/client.dart' show Client;
export 'src/client/client_keepalive.dart' show ClientKeepAliveOptions;
export 'src/client/client_transport_connector.dart'
show ClientTransportConnector;
export 'src/client/connection.dart' show ConnectionState;
Expand Down Expand Up @@ -50,6 +51,7 @@ export 'src/server/server.dart'
ServerTlsCredentials,
ConnectionServer,
Server;
export 'src/server/server_keepalive.dart' show ServerKeepAliveOptions;
export 'src/server/service.dart' show ServiceMethod, Service;
export 'src/shared/api.dart';
export 'src/shared/codec.dart' show Codec, IdentityCodec, GzipCodec;
Expand Down
10 changes: 6 additions & 4 deletions lib/src/client/client_keepalive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class ClientKeepAliveOptions {

const ClientKeepAliveOptions({
this.pingInterval,
this.timeout = const Duration(milliseconds: 20000),
this.timeout = const Duration(seconds: 20),
this.permitWithoutCalls = false,
});

Expand Down Expand Up @@ -189,7 +189,7 @@ class ClientKeepAlive {
final void Function() ping;

final ClientKeepAliveOptions _options;
Duration get _pingInterval => _options.pingInterval ?? Duration(days: 365);
Duration get _pingInterval => _options.pingInterval!;

ClientKeepAlive({
required ClientKeepAliveOptions options,
Expand Down Expand Up @@ -236,7 +236,9 @@ class ClientKeepAlive {
}

void _setState(KeepAliveEvent event) {
final newState = state.onEvent(event, this);
if (newState != null) state = newState;
if (_options.shouldSendPings) {
final newState = state.onEvent(event, this);
if (newState != null) state = newState;
}
}
}
8 changes: 5 additions & 3 deletions lib/src/server/server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class ConnectionServer {
final CodecRegistry? _codecRegistry;
final GrpcErrorHandler? _errorHandler;
final ServerKeepAliveOptions _keepAliveOptions;
final List<ServerHandler> _handlers = [];
final Map<ServerTransportConnection, List<ServerHandler>> _handlers = {};

final _connections = <ServerTransportConnection>[];

Expand All @@ -117,6 +117,7 @@ class ConnectionServer {
InternetAddress? remoteAddress,
}) async {
_connections.add(connection);
_handlers[connection] = [];
// TODO(jakobr): Set active state handlers, close connection after idle
// timeout.
final onDataReceivedController = StreamController<void>();
Expand All @@ -128,7 +129,7 @@ class ConnectionServer {
dataNotifier: onDataReceivedController.stream,
).handle();
connection.incomingStreams.listen((stream) {
_handlers.add(serveStream_(
_handlers[connection]!.add(serveStream_(
stream: stream,
clientCertificate: clientCertificate,
remoteAddress: remoteAddress,
Expand All @@ -143,10 +144,11 @@ class ConnectionServer {
// half-closed tcp streams.
// Half-closed streams seems to not be fully supported by package:http2.
// https://github.com/dart-lang/http2/issues/42
for (var handler in _handlers) {
for (var handler in _handlers[connection]!) {
handler.cancel();
}
_connections.remove(connection);
_handlers.remove(connection);
await onDataReceivedController.close();
});
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/server/server_keepalive.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ class ServerKeepAliveOptions {
final Duration minIntervalBetweenPingsWithoutData;

const ServerKeepAliveOptions({
this.minIntervalBetweenPingsWithoutData =
const Duration(milliseconds: 300000),
this.minIntervalBetweenPingsWithoutData = const Duration(minutes: 5),
this.maxBadPings = 2,
});
}
Expand Down
1 change: 0 additions & 1 deletion test/keepalive_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import 'package:grpc/grpc.dart';
import 'package:grpc/src/client/client_keepalive.dart';
import 'package:grpc/src/client/connection.dart';
import 'package:grpc/src/client/http2_connection.dart';
import 'package:grpc/src/server/server_keepalive.dart';
import 'package:http2/transport.dart';
import 'package:test/test.dart';

Expand Down
1 change: 0 additions & 1 deletion test/src/client_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'dart:convert';

import 'package:grpc/grpc.dart';
import 'package:grpc/src/client/channel.dart' as base;
import 'package:grpc/src/client/client_keepalive.dart';
import 'package:grpc/src/client/http2_connection.dart';
import 'package:grpc/src/shared/message.dart';
import 'package:http2/transport.dart';
Expand Down

0 comments on commit 9e65565

Please sign in to comment.