- Notifications
You must be signed in to change notification settings - Fork5.2k
Commit42b1480
committed
libpq: Complain about missing BackendKeyData later with PGgetCancel()
PostgreSQL always sends the BackendKeyData message at connectionstartup, but there are some third party backend implementations outthere that don't support cancellation, and don't send the message[1]. While the protocol docs left it up for interpretation if that isvalid behavior, libpq in PostgreSQL 17 and below accepted it. It doesnot seem like the libpq behavior was intentional though, since it didso by sending CancelRequest messages with all zeros to such servers(instead of returning an error or making the cancel a no-op).In version 18 the behavior was changed to return an error when tryingto create the cancel object with PGgetCancel() or PGcancelCreate().This was done without any discussion, as part of supporting differentlengths of cancel packets for the new 3.2 version of the protocol.This commit changes the behavior of PGgetCancel() / PGcancel() oncemore to only return an error when the cancel object is actually usedto send a cancellation, instead of when merely creating the object.The reason to do so is that some clients [2] create a cancel object aspart of their connection creation logic (thus having the cancel objectready for later when they need it), so if creating the cancel objectreturns an error, the whole connection attempt fails. By delaying theerror, such clients will still be able to connect to the third partybackend implementations in question, but when actually trying tocancel a query, the user will be notified that that is not possiblefor the server that they are connected to.This commit only changes the behavior of the older PGgetCancel() /PQcancel() functions, not the more modern PQcancelCreate() family offunctions. I.e. PQcancelCreate() returns a failed connection object(CONNECTION_BAD) if the server didn't send a cancellation key. Unlikethe old PQgetCancel() function, we're not aware of any clients in thefield that use PQcancelCreate() during connection startup in a waythat would prevent connecting to such servers.[1] AWS RDS Proxy is definitely one of them, and CockroachDB might beanother.[2] psycopg2 (but not psycopg3).Author: Jelte Fennema-Nio <postgres@jeltef.nl>Reviewed-by: Jacob Champion <jacob.champion@enterprisedb.com>Backpatch-through: 18Discussion:https://www.postgresql.org/message-id/20250617.101056.1437027795118961504.ishii%40postgresql.org1 parentd9f01a2 commit42b1480
2 files changed
+32
-1
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
537 | 537 | | |
538 | 538 | | |
539 | 539 | | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
540 | 545 | | |
541 | 546 | | |
542 | 547 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
379 | 379 | | |
380 | 380 | | |
381 | 381 | | |
382 | | - | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
383 | 400 | | |
384 | 401 | | |
385 | 402 | | |
| |||
544 | 561 | | |
545 | 562 | | |
546 | 563 | | |
| 564 | + | |
| 565 | + | |
| 566 | + | |
| 567 | + | |
| 568 | + | |
| 569 | + | |
| 570 | + | |
| 571 | + | |
| 572 | + | |
547 | 573 | | |
548 | 574 | | |
549 | 575 | | |
| |||
0 commit comments
Comments
(0)