<commit_before>'use strict'

const hashring = require('swim-hashring')
const EE = require('events').EventEmitter
const inherits = require('util').inherits
const net = require('net')
const tentacoli = require('tentacoli')
const pump = require('pump')
const dezalgo = require('fastzalgo')
const networkAddress = require('network-address')
const bloomrun = require('bloomrun')
const tinysonic = require('tinysonic')
const tracker = require('./lib/tracker')
const pino = require('pino')

function UpRing (opts) {
  if (!(this instanceof UpRing)) {
    return new UpRing(opts)
  }

  opts = opts || {}
  opts.port = opts.port || 0
  opts.host = opts.host || networkAddress()

  const hashringOpts = opts.hashring || {}
  hashringOpts.base = hashringOpts.base || opts.base
  hashringOpts.name = hashringOpts.name || opts.name
  hashringOpts.client = hashringOpts.client || opts.client
  hashringOpts.host = opts.host

  this._inbound = new Set()
  this.logger = opts.logger || pino()

  if (!opts.logger) {
    this.logger.level = opts.logLevel || 'info'
  }

  this._dispatch = (req, reply) => {
    var func
    if (this._router) {
      func = this._router.lookup(req)
      if (func) {
        func(req, reply)
      } else {
        reply(new Error('message does not match any pattern'))
      }
    } else {
      this.emit('request', req, reply)
    }
  }

  this._server = net.createServer((stream) => {
    if (this.closed) {
      stream.destroy()
      return
    }

    this.logger.debug({ address: stream.address() }, 'incoming connection')

    const instance = tentacoli()
    this._inbound.add(instance)
    pump(stream, instance, stream, () => {
      this.logger.debug({ address: stream.address() }, 'closed connection')
      this._inbound.delete(instance)
    })
    instance.on('request', this._dispatch)
  })
  this._server.listen(opts.port, opts.host, () => {
    this.logger.debug({ address: this._server.address() }, 'listening')
    const local = hashringOpts.local = hashringOpts.local || {}<commit_msg>Ignore errors  on incoming streams if the instance is closed<commit_after>'use strict'

const hashring = require('swim-hashring')
const EE = require('events').EventEmitter
const inherits = require('util').inherits
const net = require('net')
const tentacoli = require('tentacoli')
const pump = require('pump')
const dezalgo = require('fastzalgo')
const networkAddress = require('network-address')
const bloomrun = require('bloomrun')
const tinysonic = require('tinysonic')
const tracker = require('./lib/tracker')
const pino = require('pino')

function UpRing (opts) {
  if (!(this instanceof UpRing)) {
    return new UpRing(opts)
  }

  opts = opts || {}
  opts.port = opts.port || 0
  opts.host = opts.host || networkAddress()

  const hashringOpts = opts.hashring || {}
  hashringOpts.base = hashringOpts.base || opts.base
  hashringOpts.name = hashringOpts.name || opts.name
  hashringOpts.client = hashringOpts.client || opts.client
  hashringOpts.host = opts.host

  this._inbound = new Set()
  this.logger = opts.logger || pino()

  if (!opts.logger) {
    this.logger.level = opts.logLevel || 'info'
  }

  this._dispatch = (req, reply) => {
    var func
    if (this._router) {
      func = this._router.lookup(req)
      if (func) {
        func(req, reply)
      } else {
        reply(new Error('message does not match any pattern'))
      }
    } else {
      this.emit('request', req, reply)
    }
  }

  this._server = net.createServer((stream) => {
    if (this.closed) {
      stream.on('error', noop)
      stream.destroy()
      return
    }

    this.logger.debug({ address: stream.address() }, 'incoming connection')

    const instance = tentacoli()
    this._inbound.add(instance)
    pump(stream, instance, stream, () => {
      this.logger.debug({ address: stream.address() }, 'closed connection')
      this._inbound.delete(instance)
    })
    instance.on('request', this._dispatch)
  })
  this._server.listen(opts.port, opts.host, () => {
    this.logger.debug({ address: this._server.address() }, 'listening')
    const local = hashringOpts.local = hashringOpts.local || {}
{'fraction_non_alphanumeric': 0.14881240911294233, 'fraction_numerical': 0.0004847309743092584, 'mean_word_length': 3.418629550321199, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '4167430', 'n_tokens_mistral': 1306, 'n_tokens_neox': 1297, 'n_words': 295}