<commit_before>package hystrix

import (
	"io"
	"net/http"
	"net/url"

	"fmt"

	log "github.com/Sirupsen/logrus"
	"github.com/afex/hystrix-go/hystrix"
)

type HTTPClient struct {
	http.Client
	HystrixCommandName string
}

func NewClient(commandName string) *HTTPClient {
	return &HTTPClient{
		HystrixCommandName: commandName,
	}
}

func circuitBreaker(u, commandName string, fn func() (*http.Response, error)) (*http.Response, error) {

	output := make(chan *http.Response, 1)
	errors := make(chan error, 1)

	hystrix.Go(commandName, func() error {
		response, err := fn()
		if err != nil {
			errors <- err
		} else {
			output <- response
			if response.StatusCode == http.StatusInternalServerError {
				return fmt.Errorf("error %d", response.StatusCode)
			}
		}

		return err
	}, func(err error) error {
		log.WithError(err).WithFields(log.Fields{"commandName": commandName, "URL": u}).
			Info("breaker closed")
		return err<commit_msg>Close the channels created in hystrix client's circuit breaker<commit_after>package hystrix

import (
	"io"
	"net/http"
	"net/url"

	"fmt"

	log "github.com/Sirupsen/logrus"
	"github.com/afex/hystrix-go/hystrix"
)

type HTTPClient struct {
	http.Client
	HystrixCommandName string
}

func NewClient(commandName string) *HTTPClient {
	return &HTTPClient{
		HystrixCommandName: commandName,
	}
}

func circuitBreaker(u, commandName string, fn func() (*http.Response, error)) (*http.Response, error) {

	output := make(chan *http.Response, 1)
	defer close(output)
	errors := make(chan error, 1)
	defer close(errors)

	hystrix.Go(commandName, func() error {
		response, err := fn()
		if err != nil {
			errors <- err
		} else {
			output <- response
			if response.StatusCode == http.StatusInternalServerError {
				return fmt.Errorf("error %d", response.StatusCode)
			}
		}

		return err
	}, func(err error) error {
		log.WithError(err).WithFields(log.Fields{"commandName": commandName, "URL": u}).
			Info("breaker closed")
		return err
{'fraction_non_alphanumeric': 0.1340414769853313, 'fraction_numerical': 0.0020232675771370764, 'mean_word_length': 4.218997361477572, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6465035', 'n_tokens_mistral': 738, 'n_tokens_neox': 678, 'n_words': 163}