B
B
beduin012021-04-28 13:03:47
PostgreSQL
beduin01, 2021-04-28 13:03:47

How is timeout in PostgreSQLConnection different from timeout in query?

@override
  Future<PostgreSQLResult> query(
    String fmtString, {
    Map<String, dynamic> substitutionValues,
    bool allowReuse,
    int timeoutInSeconds,
  }) =>
      _query(
        fmtString,
        substitutionValues: substitutionValues,
        allowReuse: allowReuse,
        timeoutInSeconds: timeoutInSeconds,
      );


And there is:
class PostgreSQLConnection extends Object
    with _PostgreSQLExecutionContextMixin
    implements PostgreSQLExecutionContext {
  /// Creates an instance of [PostgreSQLConnection].
  ///
  /// [host] must be a hostname, e.g. "foobar.com" or IP address. Do not include scheme or port.
  /// [port] is the port to connect to the database on. It is typically 5432 for default PostgreSQL settings.
  /// [databaseName] is the name of the database to connect to.
  /// [username] and [password] are optional if the database requires user authentication.
  /// [timeoutInSeconds] refers to the amount of time [PostgreSQLConnection] will wait while establishing a connection before it gives up.
  /// [queryTimeoutInSeconds] refers to the default timeout for [PostgreSQLExecutionContext]'s execute and query methods.
  /// [timeZone] is the timezone the connection is in. Defaults to 'UTC'.
  /// [useSSL] when true, uses a secure socket when connecting to a PostgreSQL database.
  PostgreSQLConnection(
    this.host,
    this.port,
    this.databaseName, {
    this.username,
    this.password,
    this.timeoutInSeconds = 30,
    this.queryTimeoutInSeconds = 30,
    this.timeZone = 'UTC',
    this.useSSL = false,
    this.isUnixSocket = false,
  }) {
    _connectionState = _PostgreSQLConnectionStateClosed();
    _connectionState.connection = this;
  }


What timeout to use?

Now I have this:
List<List<dynamic>> result = await connection.query(body['sql']).timeout(Duration(seconds: 90));


But the code periodically crashes with: "TimeoutException after 0:00:30.000000: Future not completed" as if it were not 90 seconds, but 30. Accordingly, 30 seconds is set in the PostgreSQLConnection.

But I cannot understand how one timeout differs from another.

void main() async {

  connection = PostgreSQLConnection('localhost', 5432, 'db', username: 'postgres', password: '123456');
  await connection.open();

// далее сам код.

Connection like on idea once should be created? How then can it fall?

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question