Skip to content
Closed
Show file tree
Hide file tree
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
13 changes: 3 additions & 10 deletions src/connection/UndiciConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@

/* eslint-disable @typescript-eslint/restrict-template-expressions */

import { EventEmitter } from 'events'
import Debug from 'debug'
import buffer from 'buffer'
import { TLSSocket } from 'tls'
Expand All @@ -41,7 +40,7 @@ import {
TimeoutError
} from '../errors'
import { UndiciAgentOptions } from '../types'
import { kCaFingerprint, kEmitter } from '../symbols'
import { kCaFingerprint } from '../symbols'

const debug = Debug('elasticsearch')
const INVALID_PATH_REGEX = /[^\u0021-\u00ff]/
Expand All @@ -50,7 +49,6 @@ const MAX_STRING_LENGTH = buffer.constants.MAX_STRING_LENGTH

export default class Connection extends BaseConnection {
pool: Pool
[kEmitter]: EventEmitter

constructor (opts: ConnectionOptions) {
super(opts)
Expand All @@ -67,7 +65,6 @@ export default class Connection extends BaseConnection {
throw new ConfigurationError('Bad agent configuration for Undici agent')
}

this[kEmitter] = new EventEmitter()
const undiciOptions: Pool.Options = {
keepAliveTimeout: 600e3,
keepAliveMaxTimeout: 600e3,
Expand Down Expand Up @@ -123,7 +120,7 @@ export default class Connection extends BaseConnection {
path: params.path + (params.querystring == null || params.querystring === '' ? '' : `?${params.querystring}`),
headers: Object.assign({}, this.headers, params.headers),
body: params.body,
signal: options.signal ?? this[kEmitter]
signal: options.signal ?? new AbortController().signal
}

if (requestParams.path[0] !== '/') {
Expand All @@ -140,11 +137,7 @@ export default class Connection extends BaseConnection {
if (options.timeout != null && options.timeout !== this.timeout) {
timeoutId = setTimeout(() => {
timedout = true
if (options.signal != null) {
options.signal.dispatchEvent('abort')
} else {
this[kEmitter].emit('abort')
}
requestParams.signal.dispatchEvent('abort')
}, options.timeout)
}

Expand Down
1 change: 0 additions & 1 deletion src/symbols.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ export const kNodeFilter = Symbol('node filter')
export const kNodeSelector = Symbol('node selector')
export const kJsonOptions = Symbol('secure json parse options')
export const kStatus = Symbol('status')
export const kEmitter = Symbol('event emitter')
export const kProductCheck = Symbol('product check')
export const kCaFingerprint = Symbol('ca fingerprint')
export const kMaxResponseSize = Symbol('max response size')
Expand Down