<commit_before>package beanstalk

import (
	"crypto/tls"
	"fmt"
	"net"
	"net/url"
	"time"
)

// connect tries to create a new connection to the specified URL. It returns
// a channel on which a successful connect is advertised, as well as a channel
// to abort a connection attempt in progress.
func connect(URL string, options *Options) (<-chan net.Conn, chan<- struct{}) {
	newConnection, abortConnect := make(chan net.Conn), make(chan struct{}, 1)

	socket, useTLS, _ := ParseURL(URL)

	go func() {
		var conn net.Conn
		var offerC chan net.Conn

		retry := time.NewTimer(time.Second)
		retry.Stop()

		for {
			if useTLS {
				// Create a TLS connection and perform the TLS handshake.
				if c, err := tls.Dial("tcp", socket, &tls.Config{}); c != nil {
					if err = c.Handshake(); err != nil {
						c.Close()
					} else {
						conn = c
					}
				}
			} else if c, err := net.Dial("tcp", socket); err == nil {
				conn = c
			}

			if conn != nil {
				offerC = newConnection
				options.LogInfo("New beanstalk connection to %s (local=%s)", conn.RemoteAddr().String(), conn.LocalAddr().String())
			} else {
				retry.Reset(options.ReconnectTimeout)
			}

			select {
			case <-retry.C:
			case offerC <- conn:
				return
			case <-abortConnect:
				if conn != nil {
					conn.Close()
				}<commit_msg>Add proper logging to dialing out<commit_after>package beanstalk

import (
	"crypto/tls"
	"fmt"
	"net"
	"net/url"
	"time"
)

// connect tries to create a new connection to the specified URL. It returns
// a channel on which a successful connect is advertised, as well as a channel
// to abort a connection attempt in progress.
func connect(URL string, options *Options) (<-chan net.Conn, chan<- struct{}) {
	newConnection, abortConnect := make(chan net.Conn), make(chan struct{}, 1)

	socket, useTLS, _ := ParseURL(URL)

	go func() {
		// dial tries to set up either a non-TLS or a TLS connection to the
		// host:port combo specified in socket.
		dial := func() (net.Conn, error) {
			if !useTLS {
				return net.Dial("tcp", socket)
			}

			c, err := tls.Dial("tcp", socket, &tls.Config{})
			if c != nil {
				if err = c.Handshake(); err == nil {
					return c, nil
				}
			}

			return nil, err
		}

		var offerC chan net.Conn
		var retry = time.NewTimer(time.Second)
		retry.Stop()

		// Try to establish a connection to the remote beanstalk server.
		for {
			conn, err := dial()
			if err != nil {
				retry.Reset(options.ReconnectTimeout)
				options.LogError("Beanstalk connection failed to %s: %s", URL, err)
			} else {
				offerC = newConnection
				options.LogInfo("Beanstalk connection successful to %s (%s)", URL, conn.LocalAddr().String())
			}

			select {
			case <-retry.C:
			case offerC <- conn:
				return
			case <-abortConnect:
				if conn != nil {
					conn.Close()
				}
{'fraction_non_alphanumeric': 0.13252582828642678, 'fraction_numerical': 0.0007125044531528322, 'mean_word_length': 2.841313269493844, 'pattern_counts': {'":': 0, '<': 13, '<?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': '2301343', 'n_tokens_mistral': 1095, 'n_tokens_neox': 902, 'n_words': 313}