Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug fix - V1 canHandle() should cater maxWaitTime #5

Merged
merged 1 commit into from
Apr 29, 2024

Conversation

jayjlu
Copy link
Collaborator

@jayjlu jayjlu commented Apr 28, 2024

The bug was found when we try registering V3 connector with catch all router "*", some requests which should be handled by V1 connectors but randomly being sent to the V3 catch all connector.

The root cause is that there was a bug in the WebsocketFarm (for V1), when it work out whether there are available connector for the current request, it just check the current availability. But given the fact of under traffic load, the V1 connector is possible have some delay on registering back ( as it need to create new connector socket from time to time ).

A test case (src/test/java/com/hsbc/cranker/mucranker/MultiConnectorTest.java) is added to reproduce this consistently.

The fix is to cater the wait time like below

    public boolean canHandle(String target, boolean useCatchAll) {
        final String routeKey = resolveRouteKey(target, useCatchAll);
        if (routeKey == null) return false;
        final Queue<RouterSocket> routerSockets = sockets.get(routeKey);
        if (routerSockets != null && !routerSockets.isEmpty()) return true;
        return routeLastRemovalTimes.containsKey(routeKey)
            && (System.currentTimeMillis() - routeLastRemovalTimes.get(routeKey) < this.maxWaitInMillis);
    }

The PR also including some javadoc fix.

@jayjlu jayjlu requested a review from flowerdhsbc April 28, 2024 02:34
@jayjlu jayjlu merged commit a42e54e into master Apr 29, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants