3
0
Mirror von https://github.com/PaperMC/Velocity.git synchronisiert 2024-11-17 05:20:14 +01:00

Improve continuation error handling.

Dieser Commit ist enthalten in:
Seppe Volkaerts 2020-12-15 23:08:53 +01:00
Ursprung e1d21c0c27
Commit c85be1a88f

Datei anzeigen

@ -476,7 +476,9 @@ public class VelocityEventManager implements EventManager {
try { try {
task.run(this); task.run(this);
} catch (final Throwable t) { } catch (final Throwable t) {
resumeWithException(t); // validateOnlyOnce false here so don't get an exception if the
// continuation was resumed before
resume(t, false);
} }
return !CONTINUATION_TASK_STATE.compareAndSet( return !CONTINUATION_TASK_STATE.compareAndSet(
this, TASK_STATE_EXECUTING, TASK_STATE_DEFAULT); this, TASK_STATE_EXECUTING, TASK_STATE_DEFAULT);
@ -484,18 +486,22 @@ public class VelocityEventManager implements EventManager {
@Override @Override
public void resume() { public void resume() {
resume(null); resume(null, true);
} }
void resume(final @Nullable Throwable exception) { void resume(final @Nullable Throwable exception, final boolean validateOnlyOnce) {
final boolean changed = CONTINUATION_TASK_RESUMED.compareAndSet(this, false, true);
// Only allow the continuation to be resumed once // Only allow the continuation to be resumed once
if (!CONTINUATION_TASK_RESUMED.compareAndSet(this, false, true)) { if (!changed && validateOnlyOnce) {
throw new IllegalStateException("The continuation can only be resumed once."); throw new IllegalStateException("The continuation can only be resumed once.");
} }
final HandlerRegistration registration = registrations[index]; final HandlerRegistration registration = registrations[index];
if (exception != null) { if (exception != null) {
logHandlerException(registration, exception); logHandlerException(registration, exception);
} }
if (!changed) {
return;
}
if (index + 1 == registrations.length) { if (index + 1 == registrations.length) {
// Optimization: don't schedule a task just to complete the future // Optimization: don't schedule a task just to complete the future
if (future != null) { if (future != null) {
@ -511,7 +517,7 @@ public class VelocityEventManager implements EventManager {
@Override @Override
public void resumeWithException(final Throwable exception) { public void resumeWithException(final Throwable exception) {
resume(requireNonNull(exception, "exception")); resume(requireNonNull(exception, "exception"), true);
} }
} }