Session lifecycle and cleanup
Session lifecycle and cleanup.
Creation is asynchronous
SDK creation normally reserves a session and polls until it is active. The default activation timeout is 600 seconds. A timeout can occur after a session ID has been allocated: inspect the exception and console before retrying, otherwise you may create duplicate billable sessions.
Always release both resources
The automation connection and the cloud session are separate resources. Disconnecting Puppeteer or closing the Playwright connection is not a substitute for closing the Lexmount session. Use nested try/finally blocks so a connection-close error cannot skip session cleanup; close the HTTP client last. The complete Playwright example shows this order.
Session close can begin asynchronous shutdown. If a Context is still locked, wait for final session closure and Context availability before reusing or deleting it. The Node SDK's session.close() logs some close failures rather than throwing them; for critical cleanup, verify the final session state through the console or session API. Do not treat a returned promise as proof of remote teardown.
Bound concurrency
Limit simultaneous sessions to your project's entitlement and available quota. A worker should acquire a slot, create a session, do bounded work, close it, and release the slot. Retry transient transport errors with bounded backoff; do not blindly retry create calls, authentication failures, or operations that submit a form/payment. A process kill can bypass finally: reconcile your own recorded session IDs before restarting jobs.
For Context-backed work, see persistent contexts. For retention and billing, see capabilities and pricing.
