linkedin / parseq

Asynchronous Java made easier
Apache License 2.0
1.17k stars 266 forks source link

Fix promiseAlreadyResolved exception thrown by ListenableFutureUtil #316

Closed junchuanwang closed 2 years ago

junchuanwang commented 2 years ago

Based on following stack trace

2022/01/14 13:50:52.897 [[31merror[0m] [c.l.p.p.SettablePromiseImpl] [grpc-default-executor-461] [voyager-api-notifications] [] An exception was thrown by listener
com.linkedin.parseq.promise.PromiseResolvedException: Promise has already been satisfied
    at com.linkedin.parseq.promise.SettablePromiseImpl.ensureNotDone(SettablePromiseImpl.java:156)
    at com.linkedin.parseq.promise.SettablePromiseImpl.finalizeResult(SettablePromiseImpl.java:124)
    at com.linkedin.parseq.promise.SettablePromiseImpl.doFinish(SettablePromiseImpl.java:116)
    at com.linkedin.parseq.promise.SettablePromiseImpl.done(SettablePromiseImpl.java:51)
    at com.linkedin.parseq.BaseTask.done(BaseTask.java:322)
    at com.linkedin.parseq.BaseTask.lambda$contextRun$0(BaseTask.java:209)
    at com.linkedin.parseq.promise.SettablePromiseImpl.notifyListener(SettablePromiseImpl.java:148)
    at com.linkedin.parseq.promise.SettablePromiseImpl.notifyListeners(SettablePromiseImpl.java:136)
    at com.linkedin.parseq.promise.SettablePromiseImpl.lambda$doFinish$0(SettablePromiseImpl.java:117)
    at com.linkedin.parseq.internal.Continuations.submit(Continuations.java:46)

Suspect the exception to be thrown on following location https://github.com/linkedin/parseq/blob/master/subprojects/parseq/src/main/java/com/linkedin/parseq/BaseTask.java#L200

Changes:

(1) Use a new Promise in SettableTask in ListenableFutureUtil (2) Use engines.run in unit tests