Skip to content

InstanceCache is not invalidated during Connector.close(), preventing reconnection to the same database. #509

@dat-adi

Description

@dat-adi

Hello,
I observed an issue where trying to reopen a connection to a previously accessed database causes the sql.Open() function to hang. The situation looks like the following:

  1. Connection was opened to x.db
  2. Connection to x.db was closed.
  3. Connection was opened to y.db.
  4. Connection to y.db was closed.
  5. Connection to x.db was supposed to open considering that I've closed it before but it doesn't. It just hangs indefinitely.

On delving deeper into the issue, I noticed that this originates from the InstanceCache not being invalidated. I suppose that the stale cache assumes that the connection already exists but cannot find it hence causes it to malfunction. On reading through the go bindings lib, the comments above CreateInstanceCache state that the cache should be destroyed with DestroyInstanceCache.

This function was missing from the implementation for the library, which I think is the cause of my issue. I'm not entirely sure about my solution but I propose adding in an invalidation function too which could be called when the connection is closed?

Here are the references to the code blocks where:

I'm new to this so perhaps my solution may not be the best, but I'll raise a PR open to critique.
Thanks for creating and maintaining the library!

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingunder reviewThe issue is being reviewed and discussed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions