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

Revert timeout notes and deprecations. #379

Merged
merged 1 commit into from
Sep 13, 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
8 changes: 0 additions & 8 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,6 @@
- Deprecated some logical replication message parsing method.
- Removed `@internal`-annotated methods from the public API of `ServerException` and `Severity`.
- `ServerException` may be transformed into `_PgTimeoutException` which is both `PgException` and `TimeoutException` (but no longer `ServerException`).
- The `timeout` parameters and the `SessionSettings.queryTimeout` has only a somewhat
acceptable behaviour: it triggers a timeout only in the local `Future` object, but
keeps the statement running on the server. Updated documentation, deprecated the
parameter where it doesn't make long-term sense.

**Do not rely on the combination of timeouts and query statement queueing!**
We are planning to adopt a `statement_timeout`-based implementation, which will be a
breaking change for queuing-related timeouts.

## 3.3.0

Expand Down
14 changes: 1 addition & 13 deletions lib/postgres.dart
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,7 @@ abstract class Session {
///
/// When the returned future completes, the statement must eventually be freed
/// using [Statement.dispose] to avoid resource leaks.
Future<Statement> prepare(
Object /* String | Sql */ query, {
/// NOTE: setting the timeout here affects only the local [Future] object and
/// it does not cancel the pending statement. This may change in the future.
Duration? timeout,
});
Future<Statement> prepare(Object /* String | Sql */ query);

/// Executes the [query] with the given [parameters].
///
Expand Down Expand Up @@ -178,9 +173,6 @@ abstract class Session {
parameters,
bool ignoreRows = false,
QueryMode? queryMode,

/// NOTE: setting the timeout here affects only the local [Future] object and
/// it does not cancel the pending statement. This may change in the future.
Duration? timeout,
});
}
Expand Down Expand Up @@ -258,10 +250,6 @@ abstract class Statement {
Future<Result> run(
Object? /* List<Object?|TypedValue> | Map<String, Object?|TypedValue> */
parameters, {
/// NOTE: setting the timeout here affects only the local [Future] object and
/// it does not cancel the pending statement. This may change in the future.
@Deprecated('Use the `prepare` methods\'s `timeout` parameter instead. '
'Setting this parameter may throw an error in the future, and it may be removed in a future version.')
Duration? timeout,
});

Expand Down
14 changes: 4 additions & 10 deletions lib/src/pool/pool_impl.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,17 +71,14 @@ class PoolImplementation<L> implements Pool<L> {
}

@override
Future<Statement> prepare(
Object query, {
Duration? timeout,
}) async {
Future<Statement> prepare(Object query) async {
final statementCompleter = Completer<Statement>();

unawaited(withConnection((connection) async {
_PoolStatement? poolStatement;

try {
final statement = await connection.prepare(query, timeout: timeout);
final statement = await connection.prepare(query);
poolStatement = _PoolStatement(statement);
} on Object catch (e, s) {
// Could not prepare the statement, inform the caller and stop occupying
Expand Down Expand Up @@ -303,11 +300,8 @@ class _PoolConnection implements Connection {
}

@override
Future<Statement> prepare(
Object query, {
Duration? timeout,
}) {
return _connection.prepare(query, timeout: timeout);
Future<Statement> prepare(Object query) {
return _connection.prepare(query);
}

@override
Expand Down
16 changes: 5 additions & 11 deletions lib/src/v3/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ abstract class _PgSessionBase implements Session {
} else {
// The simple query protocol does not support variables. So when we have
// parameters, we need an explicit prepare.
final prepared = await _prepare(description, timeout: timeout);
final prepared = await _prepare(description);
try {
return await prepared.run(variables, timeout: timeout);
} finally {
Expand All @@ -178,18 +178,12 @@ abstract class _PgSessionBase implements Session {
}

@override
Future<Statement> prepare(
Object query, {
Duration? timeout,
}) async {
Future<Statement> prepare(Object query) async {
_verifyStateBeforeQuery();
return await _prepare(query, timeout: timeout);
return await _prepare(query);
}

Future<_PreparedStatement> _prepare(
Object query, {
Duration? timeout,
}) async {
Future<_PreparedStatement> _prepare(Object query) async {
final conn = _connection;
final name = 's/${conn._statementCounter++}';
final description = InternalQueryDescription.wrap(
Expand All @@ -201,7 +195,7 @@ abstract class _PgSessionBase implements Session {
description.transformedSql,
statementName: name,
typeOids: description.parameterTypes?.map((e) => e?.oid).toList(),
)).optionalTimeout(timeout);
));

return _PreparedStatement(description, name, this);
}
Expand Down
Loading