plandex-ai/plandex · error · http

Error generating random pin:

Error message

Error generating random pin: 

What it means

CreateEmailVerificationHandler returns HTTP 500 'Error generating random pin: <err>' when shared.GetRandomAlphanumeric(6) fails while creating the 6-character verification PIN. This generator wraps crypto/rand and fails only when the OS cryptographic RNG is unavailable or exhausted, an extremely rare condition (e.g., getrandom(2) syscall failure). This is a server-side internal error, not something the client caused.

Source

Thrown at app/server/handlers/sessions.go:90

	if req.RequireUser && !hasAccount {
		log.Printf("User not found for email: %v\n", req.Email)
		http.Error(w, "User not found", http.StatusNotFound)
		return
	} else if req.RequireNoUser && hasAccount {
		log.Printf("User already exists for email: %v\n", req.Email)
		http.Error(w, "User already exists", http.StatusConflict)
		return
	}

	var res shared.CreateEmailVerificationResponse

	if !(os.Getenv("GOENV") == "development" && os.Getenv("LOCAL_MODE") == "1") {
		// create pin - 6 alphanumeric characters
		pinBytes, err := shared.GetRandomAlphanumeric(6)
		if err != nil {
			log.Printf("Error generating random pin: %v\n", err)
			http.Error(w, "Error generating random pin: "+err.Error(), http.StatusInternalServerError)
			return
		}

		// get sha256 hash of pin
		hashBytes := sha256.Sum256(pinBytes)
		pinHash := hex.EncodeToString(hashBytes[:])

		// create verification
		err = db.CreateEmailVerification(req.Email, req.UserId, pinHash)

		if err != nil {
			log.Printf("Error creating email verification: %v\n", err)
			http.Error(w, "Error creating email verification: "+err.Error(), http.StatusInternalServerError)
			return
		}

		err = email.SendVerificationEmail(req.Email, string(pinBytes))

View on GitHub (pinned to e2d772072e)

Solutions

  1. Retry the request - crypto/rand failures are typically transient; a second call usually succeeds.
  2. Check the full server log line 'Error generating random pin: <err>' to see the underlying crypto/rand error and address it specifically.
  3. If running in a container, verify the kernel is >= 3.17 and no seccomp/apparmor profile blocks the getrandom syscall.
  4. Ensure /dev/urandom (and /dev/random) exist and are accessible inside the container; use a standard base image rather than a heavily stripped one.
  5. For local development, set GOENV=development and LOCAL_MODE=1 to bypass PIN generation entirely (local-mode branch).

Example fix

// before (server env, broken RNG)
GOENV=production LOCAL_MODE=0 ./plandex-server
// after (temporary local workaround while RNG issue is investigated)
GOENV=development LOCAL_MODE=1 ./plandex-server
Defensive patterns

Strategy: retry

Try / catch

// server-side callers / ops: retry on 500 whose body mentions random pin
for attempt := 0; attempt < 3; attempt++ {
    resp, err := http.Post(url, "application/json", body)
    if err != nil { continue }
    if resp.StatusCode == http.StatusInternalServerError && strings.Contains(readBody(resp), "Error generating random pin") {
        time.Sleep(backoff(attempt)) // transient crypto/rand failure
        continue
    }
    break
}

Prevention

When it happens

Trigger: Calling the endpoint with GOENV != 'development' or LOCAL_MODE != '1' (the local-mode branch skips PIN generation) while the crypto/rand source fails - e.g., getrandom syscall returning EAGAIN/EINTR loops exhausted, or a container/host with a broken entropy setup.

Common situations: Running the server in a restricted/hardened container where /dev RNG or getrandom is blocked by seccomp rules; heavily stripped minimal Docker images missing RNG device setup; kernel-level entropy exhaustion on old kernels (pre-3.17 without getrandom); sandboxed CI environments.

Related errors


AI-assisted analysis of plandex-ai/plandex@e2d772072e (2026-09-05). Data as JSON: /api/errors/e79848e2534e965c. Report an issue: GitHub.