Skip to content

Logic Apps Designer: autoCreateConnectionIfPossible fires in a loop due to unguarded useEffect #9131

@Xiaoyu-Huang

Description

@Xiaoyu-Huang

Severity

P2 - High (Major functionality broken)

Describe the Bug with repro steps

Describe the bug

The useEffect in ConnectionPanel calls autoCreateConnectionIfPossible without a re-entry guard, creating a loop that produces many redundant API calls when no connections exist for a connector.

Steps to reproduce

  1. Use the consumption designer with a connector that has single auth (no connectionParameterSets), visible connection parameters, and an ARM resource ID
  2. Open the connection panel for a node using that connector where no connections of that type exist yet
  3. Observe repeated getConnections and getConnection (404) API calls in the browser network tab

Root cause

File: libs/designer/src/lib/ui/panel/connectionsPanel/connectionsPanel.tsx (line 33)

  1. ConnectionPanel mounts → useConnectionsForConnector(connectorId) returns []
  2. useEffect sees connections.length === 0 → fires autoCreateConnectionIfPossible()
  3. Inside autoCreateConnectionIfPossible, getUniqueConnectionName calls getConnectionsForConnectorqueryClient.fetchQuery writes to the same React Query cache key [connectionKey, connectorId]
  4. useConnectionsForConnector is configured with cacheTime: 0 and staleTime: 0 (libs/designer/src/lib/core/queries/connections.ts line 97) → the cache write triggers a re-render with a new array reference (still [])
  5. connections dependency in useEffect changes → effect fires again → loop repeats
  6. Each iteration calls _getUniqueConnectionNameInApiHub which makes recursive getConnection API calls (returning 404)

Why Azure Portal mostly avoids this

Most Azure Portal connectors have connectionParameterSets (multi-auth), so autoCreateConnectionIfPossible exits synchronously at the connectorHasMultiAuth check (line 418) before reaching getUniqueConnectionName. The loop only affects connectors with single auth that have visible connection parameters.

Impact

  • Many redundant getConnections and getConnection (404) API calls per connection panel open
  • For simple connectors (no visible params), multiple concurrent createConnection PUT calls may fire
  • Increased latency before the create connection panel appears

Proposed fix

Add a useRef re-entry guard to prevent concurrent invocations:

const isAutoCreatingRef = useRef(false);

useEffect(() => {
  if (
    selectedNodeId &&
    connector &&
    !connectionQuery.isLoading &&
    !connectionQuery.isError &&
    connections.length === 0 &&
    !isAutoCreatingRef.current
  ) {
    isAutoCreatingRef.current = true;
    autoCreateConnectionIfPossible({
      connector: connector as Connector,
      referenceKeys: Object.keys(references),
      operationInfo,
      skipOAuth: true,
      applyNewConnection: (connection: Connection) =>
        dispatch(updateNodeConnection({ nodeId: selectedNodeId, connection, connector: connector as Connector })),
      onSuccess: () => {
        isAutoCreatingRef.current = false;
        dispatch(closeConnectionsFlow({ nodeId: selectedNodeId }));
      },
      onManualConnectionCreation: () => {
        isAutoCreatingRef.current = false;
        dispatch(setIsCreatingConnection(true));
      },
    }).catch(() => {
      isAutoCreatingRef.current = false;
    });
  }
}, [connectionQuery.isError, connectionQuery.isLoading, connections, connector, dispatch, operationInfo, references, selectedNodeId]);

### What type of Logic App Is this happening in?

Consumption (Portal)

### Are you experiencing a regression?

_No response_

### Which operating system are you using?

Windows

### Did you refer to the TSG before filing this issue? https://aka.ms/lauxtsg

Yes

### Workflow JSON

```json

Screenshots or Videos

No response

Environment

Edge

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions