pgwirecancel

package
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 18, 2022 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var CancelSemaphore = quotapool.NewIntPool("pgwire-cancel", 256)

CancelSemaphore is a semaphore that limits the number of concurrent calls to the pgwire query cancellation endpoint. This is needed to avoid the risk of a DoS attack by malicious users that attempts to cancel random queries by spamming the request.

We hard-code a limit of 256 concurrent pgwire cancel requests (per node). We also add a 1-second penalty for failed cancellation requests, meaning that an attacker needs 1 second per guess. With an attacker randomly guessing a 32-bit secret, it would take 2^24 seconds to hit one query. If we suppose there are 256 concurrent queries actively running on a node, then it would take 2^16 seconds (18 hours) to hit any one of them.

Functions

This section is empty.

Types

type BackendKeyData

type BackendKeyData uint64

BackendKeyData is a 64-bit identifier used by the pgwire protocol to cancel queries. It is created at the time of session initialization. It contains the SQLInstanceID of the node. SQLInstanceID is an alias of int32, but we use a variable number of bits here. The leading bit will only be set if the SQLInstanceID is greater than or equal to 2^11. If it is set, the other 31 bits are used for the ID; otherwise 11 bits are used for the ID. This is safe because SQLInstanceID is always a non-negative integer. The remaining bits (either 32 bits or 52 bits) are random, and are used to uniquely identify a session on that SQL node.

See information about how Postgres uses it here: https://www.postgresql.org/docs/current/protocol-flow.html#id-1.10.5.7.9

func MakeBackendKeyData

func MakeBackendKeyData(rng *rand.Rand, sqlInstanceID base.SQLInstanceID) BackendKeyData

MakeBackendKeyData creates a new BackendKayData that contains the given SQLInstanceID. The rest of the data are random bits. The number of random bits is larger of the SQLInstanceID is small enough.

func (BackendKeyData) GetSQLInstanceID

func (b BackendKeyData) GetSQLInstanceID() base.SQLInstanceID

GetSQLInstanceID returns the SQLInstanceID that is encoded in this BackendKeyData.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL