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

non-thread-safe RouteRegistry #193

Open
alalag1 opened this issue May 10, 2022 · 0 comments
Open

non-thread-safe RouteRegistry #193

alalag1 opened this issue May 10, 2022 · 0 comments

Comments

@alalag1
Copy link
Member

alalag1 commented May 10, 2022

Expected behavior

Thread-safe & fast

Actual behavior

  • Router state(mappingLookups & uriLookups) can not be guaranteed
  • expect synchronized in deRegister()
  • too much performance loss, cause' of mappingLookups(CopyOnWriteArrayList) & uriLookups(ConcurrentHashMap)`

@Override
public void register(Route route) {
if (route == null) {
return;
}
RouteWrap routeWrap = new RouteWrap(route);
//Add synchronized to avoid same routeWraps add to router without log
synchronized (this) {
router.mappingLookups.forEach(registered -> {
if (registered.predicate.mayAmbiguousWith(routeWrap.predicate)) {
logger.warn("Found ambiguous route:\n{}\n{}", routeWrap.route, registered);
}
});
router.add(routeWrap);
}
logger.debug("Registering route: {}", route);
}
@Override
public void deRegister(Route route) {
if (route == null) {
return;
}
RouteWrap routeWrap = new RouteWrap(route);
RouteWrap target = null;
for (RouteWrap item : router.mappingLookups) {
if (isEquals(item, routeWrap)) {
target = item;
break;
}
}
if (target != null) {
logger.debug("deRegistering route: {}", route);
router.remove(target);
}
}
@Override
public Route route(RequestContext context) {
return router.route(context);
}

Steps to reproduce

Env

  • Restlight version: 1.0.0-SNAPSHOT
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

No branches or pull requests

1 participant