Getting postgres connection errors

I am getting these types of errors quite frequently and am wondering what may be causing them or how to fix them.

PGError: lost synchronization with server: got message type "T", length 1409286191 PGError: lost synchronization with server: got message type "T", length 1409286191 PGError: lost synchronization with server: got message type "T", length 1409286191 PGError: lost synchronization with server: got message type "T", length 1409286191 PGError: lost synchronization with server: got message type "T", length 1409286191 PGError: lost synchronization with server: got message type "T", length 1409286191 PGError: lost synchronization with server: got message type "e", length 980640103 PGError: lost synchronization with server: got message type "e", length 980640103 PGError: lost synchronization with server: got message type "e", length 980640103

They tend to happen after the daemon is running for a while (a day or two). Needless to say once this happens the daemon is not working anymore.

Any help in diagnosing and solving this problem would be much appreciated.

This problem started with the recent update to rails. I also think it may have to do with this statement ActiveRecord::Base.connection_pool.clear_stale_cached_connections!

The postgres mailing list tells me these errors have to do with threading in libpq.