EALREADY
Linux / POSIXERRORCommonNetworkHIGH confidence

Operation Already in Progress

Production Risk

Common in async network code; always use poll/select to manage non-blocking connect.

What this means

EALREADY (errno 114) is returned when connect() is called again on a non-blocking socket that already has a pending connect() in progress.

Why it happens
  1. 1Calling connect() again on a non-blocking socket while a previous connect() is still pending
  2. 2Race condition in async connection management
How to reproduce

Second connect() on a non-blocking socket during pending connection.

trigger — this will error
trigger — this will error
// Non-blocking connect in progress
connect(sockfd, (struct sockaddr*)&addr, sizeof(addr));
// Returns -1, errno = EINPROGRESS (first call)
// Calling connect() again before it completes:
connect(sockfd, (struct sockaddr*)&addr, sizeof(addr));
// Returns -1, errno = EALREADY

expected output

connect: Operation already in progress (EALREADY)

Fix

Use poll/select to wait for connection completion

WHEN In non-blocking connect patterns

Use poll/select to wait for connection completion
// First connect() returns EINPROGRESS — wait for POLLOUT
connect(sockfd, (struct sockaddr*)&addr, sizeof(addr));
struct pollfd pfd = { .fd = sockfd, .events = POLLOUT };
poll(&pfd, 1, 5000);  // wait up to 5s
// Check SO_ERROR to see if connected
int err = 0; socklen_t len = sizeof(err);
getsockopt(sockfd, SOL_SOCKET, SO_ERROR, &err, &len);
if (err == 0) { /* connected */ }

Why this works

poll() POLLOUT fires when the non-blocking connect completes (success or failure); SO_ERROR tells the outcome.

What not to do

Call connect() in a loop without waiting

Repeated connect() returns EALREADY until the pending connect finishes; use poll() instead.

Sources
Official documentation ↗

Linux Programmer Manual connect(2)

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Linux / POSIX errors