@@ -59,6 +59,24 @@ func (b *Batch) Queue(query string, arguments []interface{}, parameterOIDs []pgt
5959// If the batch is created from a conn Object then All queries are wrapped
6060// in a transaction. The transaction can optionally be configured with
6161// txOptions. The context is in effect until the Batch is closed.
62+ //
63+ // Warning: Send writes all queued queries before reading any results. This can
64+ // cause a deadlock if an excessive number of queries are queued. It is highly
65+ // advisable to use a timeout context to protect against this possibility.
66+ // Unfortunately, this excessive number can vary based on operating system,
67+ // connection type (TCP or Unix domain socket), and type of query. Unix domain
68+ // sockets seem to be much more susceptible to this issue than TCP connections.
69+ // However, it usually is at least several thousand.
70+ //
71+ // The deadlock occurs when the batched queries to be sent are so large that the
72+ // PostgreSQL server cannot receive it all at once. PostgreSQL received some of
73+ // the queued queries and starts executing them. As PostgreSQL executes the
74+ // queries it sends responses back. pgx will not read any of these responses
75+ // until it has finished sending. Therefore, if all network buffers are full pgx
76+ // will not be able to finish sending the queries and PostgreSQL will not be
77+ // able to finish sending the responses.
78+ //
79+ // See https://github.com/jackc/pgx/issues/374.
6280func (b * Batch ) Send (ctx context.Context , txOptions * TxOptions ) error {
6381 if b .err != nil {
6482 return b .err
0 commit comments