Why does AMPS disconnect a client with a 'name in use' error?

Follow

When a transaction log is configured, AMPS needs to be able to tell the difference between connections to be able to reliably persist and replay the message stream. AMPS uses the client name as a unique application identifier to be able to tell when a connection is a connection from a different client as compared to a new connection from the same client.

The contract between AMPS and the application is that the application must provide a client name that will uniquely and consistently identify a particular instance of the client application. The same instance of the same application should use the client name each time that instance connects, and should not use the same client name as another instance.

In this case, when AMPS receives a new connection with the same client name as an existing connection, from the same IP address, with the same credentials, AMPS disconnects the existing connection.

You may wonder why AMPS does this -- why not just use the existing connection?

AMPS does this to help applications get reconnected quickly in the event of a network outage or client restart. Clients typically use TCP/IP and may be connecting through any combination of WAN, WiFi, VPN, traversing multiple firewalls, and so on. It can be a matter of minutes before the OS notifies AMPS that a connection is closed (with TCP KeepAlive enabled -- without KeepAlive enabled, it could take forever). If AMPS were to deny a new connection until the previous connection closed, the application could be offline for minutes (or even longer).

To get applications back online quickly, AMPS makes the assumption that a new connection with the same client name (from the same IP address) is intended to replace the existing connection. AMPS disconnects the existing connection in favor of the new connection. The disconnect happens immediately: AMPS does not pause the new connection or notify the old the connection.

Have more questions? Submit a request

Comments

  • Avatar
    Dhayatker, Deepak

    If I use two HaClients with the same ConnectionName there is attempt to connection grab, where both the connections is trying to connect. And Amps continuously disconnects both connections.

    What is the best way to recover from this?

  • Avatar
    Dirk Myers

    The best way to handle this is to have applications use unique connection names for each logical instance of the application. There are suggestions in the FAQ article:

    https://support.crankuptheamps.com/hc/en-us/articles/204193268

    (Having names be unique per logical instance of the application can also help for auditing/provenance, data flow tracking, and so on -- not just to avoid problems with staying connected.)

Powered by Zendesk