Skip to content

Commit 3bafa87

Browse files
authored
Fix StandardSofaRuntimeManager mem leak (#1362)
Signed-off-by: JermaineHua <[email protected]>
1 parent cb07d25 commit 3bafa87

File tree

3 files changed

+9
-0
lines changed

3 files changed

+9
-0
lines changed

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/client/impl/ClientFactoryImpl.java

+5
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@ public void registerClient(Class<?> clientType, Object clientInstance) {
3838
clients.put(clientType, clientInstance);
3939
}
4040

41+
@Override
42+
public void destroy() {
43+
clients.clear();
44+
}
45+
4146
@SuppressWarnings("unchecked")
4247
@Override
4348
public <T> T getClient(Class<T> clazz) {

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/component/impl/StandardSofaRuntimeManager.java

+2
Original file line numberDiff line numberDiff line change
@@ -129,11 +129,13 @@ public void shutdown() throws ServiceRuntimeException {
129129
@Override
130130
public void shutDownExternally() throws ServiceRuntimeException {
131131
try {
132+
clientFactoryInternal.destroy();
132133
AbstractApplicationContext applicationContext = (AbstractApplicationContext) rootApplicationContext;
133134
// only need shutdown when root context is active
134135
if (applicationContext.isActive()) {
135136
applicationContext.close();
136137
}
138+
rootApplicationContext = null;
137139
appClassLoader = null;
138140
} catch (Throwable throwable) {
139141
throw new ServiceRuntimeException(ErrorCode.convert("01-03100"), throwable);

sofa-boot-project/sofa-boot-core/runtime-sofa-boot/src/main/java/com/alipay/sofa/runtime/spi/client/ClientFactoryInternal.java

+2
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,6 @@ public interface ClientFactoryInternal extends ClientFactory {
3131
* @param clientInstance client instance
3232
*/
3333
void registerClient(Class<?> clientType, Object clientInstance);
34+
35+
void destroy();
3436
}

0 commit comments

Comments
 (0)