Skip to content

Applying settings to database() at runtime does not reuse database connections #75

@yahermann

Description

@yahermann

Per documentation, using database() in this way:

my $dbh = database({ driver => 'SQLite', database => $filename });

causes a brand new connection to be created each time, and old connections don't get disconnected, so the max gets hits quickly.

The problem appears to be in Database.pm, lines 52-54:

if (ref $arg eq 'HASH') {
    $handle_key = $arg;
    $conn_details = _merge_settings($arg, $settings, $logger);
 } else {

Even though $arg may be the same hash, i.e., { database => "mydb", username="myuser" }, unless special precautions are taken, generating it during runtime creates a different anonymous hashref each time, therefore when used as a key, Perl treats them each as different keys. Since they're different keys, a new connection gets created with each call, and old connections/handles are not reused.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions