From 38cf31895c7b2de0b0ba8f503df6391732439d40 Mon Sep 17 00:00:00 2001 From: Sean Yang Date: Mon, 25 Nov 2024 14:32:36 +0800 Subject: [PATCH] Fix #14923 --- .../rest/mapping/DefaultRequestMappingRegistry.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java index 8ec6bf4716c..c544efce29f 100644 --- a/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java +++ b/dubbo-rpc/dubbo-rpc-triple/src/main/java/org/apache/dubbo/rpc/protocol/tri/rest/mapping/DefaultRequestMappingRegistry.java @@ -180,6 +180,7 @@ public void unregister(Invoker invoker) { if (tree == null) { return; } + lock.writeLock().lock(); try { tree.remove(mapping -> mapping.meta.getInvoker() == invoker); @@ -193,6 +194,7 @@ public void destroy() { if (tree == null) { return; } + lock.writeLock().lock(); try { tree.clear(); @@ -202,6 +204,10 @@ public void destroy() { } public HandlerMeta lookup(HttpRequest request) { + if (tree == null) { + return null; + } + String stringPath = PathUtils.normalize(request.uri()); request.setAttribute(RestConstants.PATH_ATTRIBUTE, stringPath); KeyString path = new KeyString(stringPath, restConfig.getCaseSensitiveMatchOrDefault()); @@ -365,6 +371,10 @@ private void handleNoMatch(HttpRequest request, List partialMatc @Override public boolean exists(String stringPath, String method) { + if (tree == null) { + return false; + } + KeyString path = new KeyString(stringPath, restConfig.getCaseSensitiveMatchOrDefault()); if (tryExists(path, method)) { return true;