// Package errors implements an error handling plugin.
package errors
import (
"context"
"regexp"
"sync/atomic"
"time"
"unsafe"
"github.com/coredns/coredns/plugin"
clog "github.com/coredns/coredns/plugin/pkg/log"
"github.com/coredns/coredns/request"
"github.com/miekg/dns"
)
var log = clog.NewWithPlugin("errors")
type pattern struct {
ptimer unsafe.Pointer
count uint32
period time.Duration
pattern *regexp.Regexp
}
func (p *pattern) timer() *time.Timer {
return (*time.Timer)(atomic.LoadPointer(&p.ptimer))
}
func (p *pattern) setTimer(t *time.Timer) {
atomic.StorePointer(&p.ptimer, unsafe.Pointer(t))
}
// errorHandler handles DNS errors (and errors from other plugin).
type errorHandler struct {
patterns []*pattern
stopFlag uint32
Next plugin.Handler
}
func newErrorHandler() *errorHandler {
return &errorHandler{}
}
func (h *errorHandler) logPattern(i int) {
cnt := atomic.SwapUint32(&h.patterns[i].count, 0)
if cnt > 0 {
log.Errorf("%d errors like '%s' occurred in last %s",
cnt, h.patterns[i].pattern.String(), h.patterns[i].period)
}
}
func (h *errorHandler) inc(i int) bool {
if atomic.LoadUint32(&h.stopFlag) > 0 {
return false
}
if atomic.AddUint32(&h.patterns[i].count, 1) == 1 {
ind := i
t := time.AfterFunc(h.patterns[ind].period, func() {
h.logPattern(ind)
})
h.patterns[ind].setTimer(t)
if atomic.LoadUint32(&h.stopFlag) > 0 && t.Stop() {
h.logPattern(ind)
}
}
return true
}
func (h *errorHandler) stop() {
atomic.StoreUint32(&h.stopFlag, 1)
for i := range h.patterns {
t := h.patterns[i].timer()
if t != nil && t.Stop() {
h.logPattern(i)
}
}
}
// ServeDNS implements the plugin.Handler interface.
func (h *errorHandler) ServeDNS(ctx context.Context, w dns.ResponseWriter, r *dns.Msg) (int, error) {
rcode, err := plugin.NextOrFailure(h.Name(), h.Next, ctx, w, r)
if err != nil {
strErr := err.Error()
for i := range h.patterns {
if h.patterns[i].pattern.MatchString(strErr) {
if h.inc(i) {
return rcode, err
}
break
}
}
state := request.Request{W: w, Req: r}
log.Errorf("%d %s %s: %s", rcode, state.Name(), state.Type(), strErr)
}
return rcode, err
}
// Name implements the plugin.Handler interface.
func (h *errorHandler) Name() string { return "errors" }
/bundler-string-length
dave/es5-class-helper
dave/import.meta.resolve
dave/install-tag-without-dash
dave/lol
dave/nodemodule-preloadmodules
dave/postinstall
dave/postinstall_2
dave/remove-native-event
dave/zlib
debugger-dev
derrick/fix/bindings-mark-jscinitialize
derrick/fix/event-emitter-async-iter
derrick/fix/event-emitter-emit-throw-native
derrick/fix/http-lowercase-headers
derrick/fix/node-tests
derrick/test/add-ed25519-tests
detect-libc
doc/0.8
dylan/callback-fulfilled-after-rejection
dylan/change-pathname-assert
dylan/cli-fixes
dylan/encoding-fix
dylan/fix-bundling-lodash-es-is-buffer
dylan/fix-error-inlining
dylan/fix-module-field-in-exports
dylan/github-api-option
dylan/github-dependencies
dylan/import-file-path
dylan/non-enumerable-export-values
dylan/resolve-rope-in-string
dylan/set-exit-code
dylan/source-map-names-property
eventstream
feat/ecosystem
feat/npm
fix
fix-prepare-stack-trace
fix-websocket-upgrade
fs-watch-file
got
guides-3
improve-docker
insensitive-pkg-names
integration-tests
jarred/5859
jarred/actions
jarred/add-git
jarred/analytics
jarred/arenas
jarred/ast
jarred/ast-again
jarred/async_bio
jarred/bench
jarred/brotli
jarred/bump-uws
jarred/bundle-workspace-packages
jarred/bunfig
jarred/callable
jarred/canvas
jarred/ci-check
jarred/cjs2
jarred/cleanup-error
jarred/clipboard-objc
jarred/direct
jarred/dump
jarred/edgecase
jarred/esbuild-plugin-api
jarred/escapeHTML
jarred/esm-conditions
jarred/experiment-bsp
jarred/export-star-flat
jarred/exports-map
jarred/faster-error-capturestacktrace
jarred/faster-ordered-properties
jarred/fastmalloc
jarred/fetch-experiment
jarred/fetchheaders
jarred/fix-blob-slice-test
jarred/fix-bunbun-on-wsl
jarred/fix-crash
jarred/fix-http-compression
jarred/fix-issue-with-tsconfig-run
jarred/fix-proxy-regression
jarred/fixes-3129
jarred/gen
jarred/htmlrewriter
jarred/improve-testing
jarred/inquirer
jarred/isolation
jarred/jsc
jarred/land
jarred/landing
jarred/linux
jarred/live-bindings
jarred/make-strings-better
jarred/mdx-thrwawy
jarred/move
jarred/napi
jarred/new-bund
jarred/new-bund-ressurected-branch
jarred/new-http
jarred/no-more-npm
jarred/package-mapper
jarred/pg
jarred/port
jarred/possibly-2732
jarred/postgresql
jarred/precompile-linux-dependencies
jarred/prepare-for-libuv
jarred/profiled-call
jarred/read-tsconfig-jsx
jarred/redo-evaluation-order
jarred/redo-zigstring-for-utf16
jarred/relay
jarred/rename
jarred/repl
jarred/request-finalizer
jarred/rewrite-router
jarred/run
jarred/simdjson
jarred/simplify
jarred/some-fixes-for-eventsource
jarred/standalone-repro1
jarred/start
jarred/strong
jarred/subprocess
jarred/support-tee
jarred/tcc
jarred/throw-if
jarred/update-install-stuff
jarred/update-zig1
jarred/upgrade-zig-2
jarred/uws
jarred/webkit-upgrade-may-17
jarred/wip-more-reliable
jarred/workers
jarred/zlib
jarred/zls
lithdew/picohttp-mimalloc
main
move-templates
nestjs-guide
next-cleanup
origin/main
plugin/plugindata
plugin/resolvedir
postinstall_3
repl
request-body-stream
reserve-commands
revert-5167-dylan/decode-regex-if-needed
rfc/bun-bundler-api
rfc/bunfig-overhaul
save-in-update
sdl
test/action
types/mock
types/readable-stream-default
types/tty
u/vjpr/zig-0.10
xHyroM/types/expose-Bun-Env
Unnamed repository; edit this file 'description' to name the repository.
Age Commit message (Collapse ) Author Files Lines
* Give dlopen & linkSymbols typings for exported functions
* Fix lookup table
* Fully change over to Pointer + fix examples
* add back header for typings
* Fix tsc errors
* Run formatter on ffi.d.ts
* Revert args/return type change
* Add type tests for ffi
---------
Co-authored-by: Colin McDonnell <colinmcd94@gmail.com>
* Fix Bun.sleep/sleepSync to actually use milliseconds
`Bun.sleepSync` was accidentally treating its argument as seconds rather than milliseconds as the docs stated. This is a breaking change in that the function now behaves as documented. Fixed relevant tests.
* sleepSync: add more argument checking, tests
* Add page descriptions
* Update bun install
* Description tweaks
* Tweaks
* removed redundant tests, fixed server segfault
* fix onRejectStream, safer unassign signal
* fix abort Bun.serve signal.addEventListener on async
* move ctx.signal null check up
* keep original behavior of streams onAborted
* fix(node:http/https): fix passing `URL` objs to `http.request`(#2253)
* fix(node:http): hoist debug env var
* fix(node:http): make body `undefined` when falsy
This reverts commit 7b9a17f9d7106ffd8e553a5192aba60d14ea5e9c.
This reverts commit ec20fae57f96a835562b154730957ecc4015ba31.
* avoids segfault after aborted on reject
* silence err on handleRejectStream after aborted
cc @FireTheFox
abort event behavior (#2252)
* fix deinit behavior when connection is aborted using ResponseStream
* fix abort handling on stream, and get better tests
* avoid segfault by trying to deinit 2x when aborted
* make tests more reliable
* more reliable onResolveStream after aborted
* add test case for not firing the abort signal
* fix Bun.file.arrayBuffer() segmentation fault on empty file #2248
* cleanner this.iotask check
The c-ares build expects lib/libcares.a to exist after cmake, but on my system it was being generated in lib64. This simply sets the cmake variable so that the target ends up where we expect.
Example usage:
BUN_JSC_logGC=1 bun file.js
* remove vendored clap
* Update to latest zig-clap
Major changes:
* Instead of vendoring zig-clap and adding changes, this uses Hejsil/zig-clap directly as a submodule
* `cli.zig` and related files have been updated to use new API (no more `flag()` or `option()`)
* A workaround for the Run and Auto commands has been implemented that allows us to use the official upstream
Minor change:
* `-i` now has the long option `--install-fallback`; I didn't spend much time thinking about this name, so suggestions weclome.
* add --development and --optional to bun install
* Add support for `-D`, `--dev` in bun install, fix `--save`