Skip to content

Windows/WSL2 authState race condition causing undefined state crash on Baileys startup #2553

@LuanValente

Description

@LuanValente

Problem

While running Evolution API v2.3.7 on Windows + WSL2 + Docker Desktop environments, the application randomly crashes during WhatsApp instance initialization with:

TypeError: Cannot read properties of undefined (reading 'state')

The issue happens inside:

this.instance.authState.state.creds

Environment

  • Windows 11
  • WSL2
  • Docker Desktop
  • Evolution API 2.3.7
  • Baileys

Symptoms

  • QR code loop
  • disconnected status
  • timeout on connect
  • reconnect loop
  • instance closes immediately after creation

Root Cause

A race condition during socket bootstrap allows the Baileys client to initialize before authState is fully initialized.


Fix

I created a defensive fallback validation before accessing:

this.instance.authState.state

This prevents crashes during early bootstrap on slower/containerized Windows environments.


Repository

Fix implementation and documentation:

https://github.com/LuanValente/evolution-api-wsl2-authstate-fix

Author

Developed and documented by:

Luan Valente


Credits

This repository is based on the original Evolution API project:

https://github.com/EvolutionAPI/evolution-api

All credits for the original implementation belong to the Evolution API maintainers.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions