Ticket #1072 enhancement closed wontfix

Opened 9 years ago

Last modified 7 years ago

adbapi: retrying queries on a lost connection

Reported by: davep Owned by: davep
Priority: normal Milestone:
Component: core Keywords:
Cc: davep, therve Branch:
Author: Launchpad Bug:

Description


Attachments

1072_adbapi.diff Download (2.8 KB) - added by therve 8 years ago.

Change History

1

  Changed 9 years ago by davep

The connection pool should support an option to
retry failed queries on a lost connection.

Changed 8 years ago by therve

2

  Changed 8 years ago by therve

  • keywords core removed
  • cc therve added

Attached a patch adding the option, with a testcase for the new behaviour. I don't know if it's worth putting it in the trunk, but at least it's here if someone wants it.

3

follow-up: ↓ 4   Changed 8 years ago by exarkun

What if the connection is lost on the re-attempt as well?

4

in reply to: ↑ 3   Changed 8 years ago by therve

Replying to exarkun:

What if the connection is lost on the re-attempt as well?

It only retries one time. I think that doing something smarter is really application-specific. The first retry is useful when you lost a link on a timeout/network reset, and doesn't bomb your app by retrying indefinitely. But it's a small benefit.

I saw the advantage in my apps when I restart my database: on the first query made after the restart, a ConnectionLost is raised, and I try to run the query another time: it recreates the connection and everything is fine. This way I don't need to restart the application when the database is restarted.

5

follow-up: ↓ 6   Changed 8 years ago by exarkun

Retrying once seems about the same to me as retrying twice: they're both decisions the applications should be able to make.

I'm not very familiar with this part of adbapi. Is it already possible for the application to reconnect when connection lost happens?

If so, then the mechanism exists already, and this patch just adds policy, which we should avoid - particularly policy which cannot be overridden.

6

in reply to: ↑ 5   Changed 8 years ago by therve

Replying to exarkun:

Retrying once seems about the same to me as retrying twice: they're both decisions the applications should be able to make.

Right, but I don't see the use-case for more than 1 :).

I'm not very familiar with this part of adbapi. Is it already possible for the application to reconnect when connection lost happens?

Yes and no. If you catch a ConnectionLost in the application, you have to recreate the whole pool to be sure every connections are cleaned up. By retrying in the thread pool, you recreate the connections one by one: connections are recreated only when a ConnectionLost happened on the Connection itself, not on the pool.

So if you retry in your app after a ConnectionLost, you have lots of chance to get a different connection from the first time: this connection would not have been cleaned up, and you'll get another ConnectionLost.

If so, then the mechanism exists already, and this patch just adds policy, which we should avoid - particularly policy which cannot be overridden.

I really think that you have to be in the thread to do this job, but I agree it's not necessary here: it can be done easily by subclassing ConnectionPool, which is what I do in my code.

The patch is here if someone interested and if the problem is raised again, but I guess a wontfix applies here.

7

  Changed 7 years ago by davep

  • status changed from new to closed
  • resolution set to wontfix

I'm going to resolve this as wontfix, if that's ok, therve.

Note: See TracTickets for help on using tickets.