Skip to content

Commit

Permalink
Merge pull request #133 from benjchristensen/fix-error-handling-endCu…
Browse files Browse the repository at this point in the history
…rrentThreadExecutingCommand

Fix NoSuchElementException in Hystrix.endCurrentThreadExecutingCommand
  • Loading branch information
benjchristensen committed Mar 31, 2013
2 parents 1bab5e0 + 72aa2bd commit 366f11a
Showing 1 changed file with 20 additions and 2 deletions.
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

0 comments on commit 366f11a

Please sign in to comment.