Suppose you just received the following error:
*pgconn.errTimeout: timeout: context canceled
during database operation attempts in your Go app.
Obviously, the first thing you need to check is your query, its performance, and timeout values. You might miss some index creations, etc.
If everything is ok with your query and it’s working well and constantly faster than that timeout value, the reason may be another transaction. Simply put, something or somebody might start the transaction and neglect to commit (or rollback) it.
In my case, I figured out that the DB browser IntelliJ IDEA Plugin automatically started a new transaction and required a manual commit. All the time it was hanging, the Go’s pgconn driver gave timeout errors.
If you still have any questions, feel free to ask me in the comments under this article or write me at email@example.com.
If I saved your day, you can support me 🤝