codingapi / codingapi/tx-lcn

LCN debug time out, occur NullPointException and lock db record.

Abierto
#464 0 comentarios 0 reacciones 0 asignados Ver en GitHub
Lenguaje dominante
Java
Estrellas
4.2k
Forks
1.4k
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

Although others also meet the similar situation, the exception seems not same.

### 1. Bug Description
When I debug in LCN model, it throw the "dtx timeout" LCNBusinessException. And when it catch the exception and handle, NullPointException is thrown in the handler logic.
What's more, it also lock the table dbs.
If I really run in timeout situation, I think NullPointException will be thrown as well.

### 2. Environment:
- JDK version: 1.8
- OS: window 10
- TX-LCN version: 5.0.0.RELEASE
- Others:

### 3. Exception Stacktrace
```
java.lang.NullPointerException: null
at com.codingapi.txlcn.tc.core.checking.DefaultDTXExceptionHandler.handleNotifyGroupBusinessException(DefaultDTXExceptionHandler.java:97)
at com.codingapi.txlcn.tc.core.template.TransactionControlTemplate.notifyGroup(TransactionControlTemplate.java:159)
at com.codingapi.txlcn.tc.core.transaction.lcn.control.LcnStartingTransaction.postBusinessCode(LcnStartingTransaction.java:65)
at com.codingapi.txlcn.tc.core.DTXServiceExecutor.transactionRunning(DTXServiceExecutor.java:109)
at com.codingapi.txlcn.tc.aspect.weave.DTXLogicWeaver.runTransaction(DTXLogicWeaver.java:95)
at com.codingapi.txlcn.tc.aspect.TransactionAspect.runWithLcnTransaction(TransactionAspect.java:93)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethodWithGivenArgs(AbstractAspectJAdvice.java:644)
at org.springframework.aop.aspectj.AbstractAspectJAdvice.invokeAdviceMethod(AbstractAspectJAdvice.java:633)
at org.springframework.aop.aspectj.AspectJAroundAdvice.invoke(AspectJAroundAdvice.java:70)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:175)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:93)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:688)
```

### 4. Code
TransactionControlTemplate.java
```
public void notifyGroup(String groupId, String unitId, String transactionType, int state) {
try {
this.txLogger.transactionInfo(groupId, unitId, "notify group > {} > groupId: {xid}, unitId: {uid}, state: {}.", new Object[]{transactionType, state});
if (this.globalContext.isDTXTimeout()) {
throw new LcnBusinessException("dtx timeout.");
}

this.reliableMessenger.notifyGroup(groupId, state);
this.transactionCleanTemplate.clean(groupId, unitId, transactionType, state);
log.debug("{} > close transaction group.", transactionType);
} catch (TransactionClearException var6) {
log.error("clear exception", var6);
this.txLogger.trace(groupId, unitId, "Transaction Error", "clean transaction fail.", new Object[0]);
} catch (RpcException var7) {
this.dtxExceptionHandler.handleNotifyGroupMessageException(Arrays.asList(groupId, state, unitId, transactionType), var7);
} catch (LcnBusinessException var8) {
this.dtxExceptionHandler.handleNotifyGroupBusinessException(Arrays.asList(groupId, state, unitId, transactionType), var8.getCause());
}

this.txLogger.transactionInfo(groupId, unitId, "notify group exception state %d.", new Object[]{state});
}
```
DefaultDTXExceptionHandler.java
```
public void handleNotifyGroupBusinessException(Object params, Throwable ex) {
List paramList = (List)params;
String groupId = (String)paramList.get(0);
int state = (Integer)paramList.get(1);
String unitId = (String)paramList.get(2);
String transactionType = (String)paramList.get(3);

/*
* need to validate the ex whether is null
*/

if (ex instanceof UserRollbackException) {
state = 0;
}

if (ex.getCause() != null && ex.getCause() instanceof UserRollbackException) {
state = 0;
}

try {
this.transactionCleanTemplate.clean(groupId, unitId, transactionType, state);
} catch (TransactionClearException var9) {
log.error("{} > clean transaction error.", transactionType);
}
}
```

### 5. Tour Idea
Do a validation in DefaultDTXExceptionHandler.handleNotifyGroupBusinessException, validate whether the ex is null at first. Also need the validation in the similar code.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Start with DefaultDTXExceptionHandler.handleNotifyGroupBusinessException and the call from TransactionControlTemplate.notifyGroup, where the timeout exception's cause is passed in. Review the similar exception-handling code mentioned in the issue. Done means timeout handling no longer dereferences a null cause and the transaction cleanup path remains protected from the reported NullPointerException.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
java
Área
distributed-systems
Tipo de issue
Error
Dificultad
2/5
Tiempo estimado
1-3 horas
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
45/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.