Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix NoSuchElementException in Hystrix.endCurrentThreadExecutingCommand #133

Merged
merged 1 commit into from
Mar 31, 2013
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions hystrix-core/src/main/java/com/netflix/hystrix/Hystrix.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
import static org.junit.Assert.*;

import java.util.LinkedList;
import java.util.NoSuchElementException;
import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.netflix.hystrix.HystrixCommand.Setter;
import com.netflix.hystrix.HystrixCommandProperties.ExecutionIsolationStrategy;
Expand All @@ -15,6 +18,8 @@
*/
public class Hystrix {

private static final Logger logger = LoggerFactory.getLogger(Hystrix.class);

/**
* Reset state and release resources in use (such as thread-pools).
* <p>
Expand Down Expand Up @@ -81,11 +86,24 @@ public static HystrixCommandKey getCurrentThreadExecutingCommand() {
}

/* package */static void startCurrentThreadExecutingCommand(HystrixCommandKey key) {
currentCommand.get().push(key);
try {
currentCommand.get().push(key);
} catch (Exception e) {
logger.warn("Unable to record command starting", e);
}
}

/* package */static void endCurrentThreadExecutingCommand() {
currentCommand.get().pop();
try {
if (!currentCommand.get().isEmpty()) {
currentCommand.get().pop();
}
} catch (NoSuchElementException e) {
// this shouldn't be possible since we check for empty above and this is thread-isolated
logger.debug("No command found to end.", e);
} catch (Exception e) {
logger.warn("Unable to end command.", e);
}
}

public static class UnitTest {
Expand Down