Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

patch: v2.5.9 #641

Merged
merged 5 commits into from
Sep 26, 2024
Merged
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
2 changes: 1 addition & 1 deletion .github/workflows/gh-translator.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ jobs:
with:
BOT_GITHUB_TOKEN: ${{ secrets.GH_TRANSLATOR_TOKEN }}
IS_MODIFY_TITLE: true
CUSTOM_BOT_NOTE: 🤖 Non-English text detected, translating...
CUSTOM_BOT_NOTE: 🤖 Non-English text detected, translating ...
48 changes: 48 additions & 0 deletions .github/workflows/stale-bot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Monitor inactive issues and PRs
on:
schedule:
- cron: '0 0 * * *'
workflow_dispatch:

jobs:
stale-issues:
runs-on: ubuntu-latest
permissions:
actions: write
issues: write
pull-requests: write
steps:
- uses: actions/stale@v9
with:
operations-per-run: 100
days-before-issue-stale: 30
days-before-issue-close: 7
stale-issue-label: 'stale'
stale-issue-message: |
This issue is marked as stale because it has been open for 30 days with no activity.

You should take one of the following actions:
- Manually close this issue if it is no longer relevant
- Comment if you have more information to share

This issue will be automatically closed in 7 days if no further activity occurs.
close-issue-message: |
This issue was closed because it has been inactive for 7 days since being marked as stale.

If you believe this is a false alarm, please leave a comment for it or open a new issue, you can also reopen this issue directly if you have permission.
days-before-pr-stale: 21
days-before-pr-close: 7
stale-pr-label: 'stale'
stale-pr-message: |
This PR is marked as stale because it has been open for 21 days with no activity.

You should take one of the following actions:
- Manually close this PR if it is no longer relevant
- Push new commits or comment if you have more information to share

This PR will be automatically closed in 7 days if no further activity occurs.
close-pr-message: |
This PR was closed because it has been inactive for 7 days since being marked as stale.

If you believe this is a false alarm, feel free to reopen this PR or create a new one.
repo-token: ${{ secrets.GITHUB_TOKEN }}
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ Become a bronze sponsor with a monthly donation of $10 and get your logo on our

# 🔑 JetBrains OS licenses

`gnet` had been being developed with `GoLand` IDE under the **free JetBrains Open Source license(s)** granted by JetBrains s.r.o., hence I would like to express my thanks here.
`gnet` has been being developed with `GoLand` IDE under the ***free JetBrains Open Source license(s)*** granted by JetBrains s.r.o., hence I would like to express my thanks here.

<a href="https://www.jetbrains.com/?from=gnet" target="_blank"><img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/jetbrains/jetbrains-variant-4.png" width="250" align="middle"/></a>
<a href="https://www.jetbrains.com/?from=gnet" target="_blank"><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg" alt="JetBrains logo."></a>

# 🔋 Sponsorship

Expand Down
4 changes: 2 additions & 2 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -246,9 +246,9 @@ Test duration : 15s

# 🔑 JetBrains 开源证书支持

`gnet` 项目一直以来都是在 JetBrains 公司旗下的 GoLand 集成开发环境中进行开发,基于 **free JetBrains Open Source license(s)** 正版免费授权,在此表达我的谢意。
`gnet` 项目一直以来都是在 JetBrains 公司旗下的 GoLand 集成开发环境中进行开发,基于 ***free JetBrains Open Source license(s)*** 正版免费授权,在此表达我的谢意。

<a href="https://www.jetbrains.com/?from=gnet" target="_blank"><img src="https://raw.githubusercontent.com/panjf2000/illustrations/master/jetbrains/jetbrains-variant-4.png" width="250" align="middle"/></a>
<a href="https://www.jetbrains.com/?from=gnet" target="_blank"><img src="https://resources.jetbrains.com/storage/products/company/brand/logos/jetbrains.svg" alt="JetBrains logo."></a>

# 🔋 赞助商

Expand Down
10 changes: 2 additions & 8 deletions acceptor_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,7 @@ func (eng *engine) listenStream(ln net.Listener) (err error) {
if atomic.LoadInt32(&eng.beingShutdown) == 0 {
eng.opts.Logger.Errorf("Accept() fails due to error: %v", err)
} else if errors.Is(err, net.ErrClosed) {
err = errorx.ErrEngineShutdown
// TODO: errors.Join() is not supported until Go 1.20,
// we will uncomment this line after we bump up the
// minimal supported go version to 1.20.
// err = errors.Join(err, errorx.ErrEngineShutdown)
err = errors.Join(err, errorx.ErrEngineShutdown)
}
return
}
Expand Down Expand Up @@ -81,9 +77,7 @@ func (eng *engine) ListenUDP(pc net.PacketConn) (err error) {
if atomic.LoadInt32(&eng.beingShutdown) == 0 {
eng.opts.Logger.Errorf("failed to receive data from UDP fd due to error:%v", err)
} else if errors.Is(err, net.ErrClosed) {
err = errorx.ErrEngineShutdown
// TODO: ditto.
// err = errors.Join(err, errorx.ErrEngineShutdown)
err = errors.Join(err, errorx.ErrEngineShutdown)
}
return
}
Expand Down
9 changes: 5 additions & 4 deletions engine_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ package gnet

import (
"context"
"errors"
"runtime"
"strings"
"sync"
Expand All @@ -29,7 +30,7 @@ import (
"github.com/panjf2000/gnet/v2/internal/gfd"
"github.com/panjf2000/gnet/v2/internal/netpoll"
"github.com/panjf2000/gnet/v2/internal/queue"
"github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -59,7 +60,7 @@ func (eng *engine) isInShutdown() bool {

// shutdown signals the engine to shut down.
func (eng *engine) shutdown(err error) {
if err != nil && err != errors.ErrEngineShutdown {
if err != nil && !errors.Is(err, errorx.ErrEngineShutdown) {
eng.opts.Logger.Errorf("engine is being shutdown with error: %v", err)
}

Expand Down Expand Up @@ -211,14 +212,14 @@ func (eng *engine) stop(s Engine) {

// Notify all event-loops to exit.
eng.eventLoops.iterate(func(i int, el *eventloop) bool {
err := el.poller.Trigger(queue.HighPriority, func(_ interface{}) error { return errors.ErrEngineShutdown }, nil)
err := el.poller.Trigger(queue.HighPriority, func(_ interface{}) error { return errorx.ErrEngineShutdown }, nil)
if err != nil {
eng.opts.Logger.Errorf("failed to enqueue shutdown signal of high-priority for event-loop(%d): %v", i, err)
}
return true
})
if eng.ingress != nil {
err := eng.ingress.poller.Trigger(queue.HighPriority, func(_ interface{}) error { return errors.ErrEngineShutdown }, nil)
err := eng.ingress.poller.Trigger(queue.HighPriority, func(_ interface{}) error { return errorx.ErrEngineShutdown }, nil)
if err != nil {
eng.opts.Logger.Errorf("failed to enqueue shutdown signal of high-priority for main event-loop: %v", err)
}
Expand Down
24 changes: 8 additions & 16 deletions internal/netpoll/poller_epoll_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package netpoll

import (
"errors"
"os"
"runtime"
"sync/atomic"
Expand All @@ -27,7 +28,7 @@ import (
"golang.org/x/sys/unix"

"github.com/panjf2000/gnet/v2/internal/queue"
"github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -133,12 +134,9 @@ func (p *Poller) Polling(callback PollEventHandler) error {
if fd := int(ev.Fd); fd == p.efd { // poller is awakened to run tasks in queues.
doChores = true
} else {
switch err = callback(fd, ev.Events, 0); err {
case nil:
case errors.ErrAcceptSocket, errors.ErrEngineShutdown:
err = callback(fd, ev.Events, 0)
if errors.Is(err, errorx.ErrAcceptSocket) || errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in event-loop: %v", err)
}
}
}
Expand All @@ -147,25 +145,19 @@ func (p *Poller) Polling(callback PollEventHandler) error {
doChores = false
task := p.urgentAsyncTaskQueue.Dequeue()
for ; task != nil; task = p.urgentAsyncTaskQueue.Dequeue() {
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
for i := 0; i < MaxAsyncTasksAtOneTime; i++ {
if task = p.asyncTaskQueue.Dequeue(); task == nil {
break
}
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
Expand Down
24 changes: 8 additions & 16 deletions internal/netpoll/poller_epoll_ultimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package netpoll

import (
"errors"
"os"
"runtime"
"sync/atomic"
Expand All @@ -26,7 +27,7 @@ import (
"golang.org/x/sys/unix"

"github.com/panjf2000/gnet/v2/internal/queue"
"github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -135,12 +136,9 @@ func (p *Poller) Polling() error {
if pollAttachment.FD == p.epa.FD { // poller is awakened to run tasks in queues.
doChores = true
} else {
switch err = pollAttachment.Callback(pollAttachment.FD, ev.events, 0); err {
case nil:
case errors.ErrAcceptSocket, errors.ErrEngineShutdown:
err = pollAttachment.Callback(pollAttachment.FD, ev.events, 0)
if errors.Is(err, errorx.ErrAcceptSocket) || errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in event-loop: %v", err)
}
}
}
Expand All @@ -149,25 +147,19 @@ func (p *Poller) Polling() error {
doChores = false
task := p.urgentAsyncTaskQueue.Dequeue()
for ; task != nil; task = p.urgentAsyncTaskQueue.Dequeue() {
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
for i := 0; i < MaxAsyncTasksAtOneTime; i++ {
if task = p.asyncTaskQueue.Dequeue(); task == nil {
break
}
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
Expand Down
24 changes: 8 additions & 16 deletions internal/netpoll/poller_kqueue_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,15 @@
package netpoll

import (
"errors"
"os"
"runtime"
"sync/atomic"

"golang.org/x/sys/unix"

"github.com/panjf2000/gnet/v2/internal/queue"
"github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -118,12 +119,9 @@ func (p *Poller) Polling(callback PollEventHandler) error {
doChores = true
p.drainWakeupEvent()
} else {
switch err = callback(fd, ev.Filter, ev.Flags); err {
case nil:
case errors.ErrAcceptSocket, errors.ErrEngineShutdown:
err = callback(fd, ev.Filter, ev.Flags)
if errors.Is(err, errorx.ErrAcceptSocket) || errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in event-loop: %v", err)
}
}
}
Expand All @@ -132,25 +130,19 @@ func (p *Poller) Polling(callback PollEventHandler) error {
doChores = false
task := p.urgentAsyncTaskQueue.Dequeue()
for ; task != nil; task = p.urgentAsyncTaskQueue.Dequeue() {
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
for i := 0; i < MaxAsyncTasksAtOneTime; i++ {
if task = p.asyncTaskQueue.Dequeue(); task == nil {
break
}
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
Expand Down
24 changes: 8 additions & 16 deletions internal/netpoll/poller_kqueue_ultimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package netpoll

import (
"errors"
"os"
"runtime"
"sync/atomic"
Expand All @@ -27,7 +28,7 @@ import (
"golang.org/x/sys/unix"

"github.com/panjf2000/gnet/v2/internal/queue"
"github.com/panjf2000/gnet/v2/pkg/errors"
errorx "github.com/panjf2000/gnet/v2/pkg/errors"
"github.com/panjf2000/gnet/v2/pkg/logging"
)

Expand Down Expand Up @@ -120,12 +121,9 @@ func (p *Poller) Polling() error {
p.drainWakeupEvent()
} else {
pollAttachment := restorePollAttachment(unsafe.Pointer(&ev.Udata))
switch err = pollAttachment.Callback(int(ev.Ident), ev.Filter, ev.Flags); err {
case nil:
case errors.ErrAcceptSocket, errors.ErrEngineShutdown:
err = pollAttachment.Callback(int(ev.Ident), ev.Filter, ev.Flags)
if errors.Is(err, errorx.ErrAcceptSocket) || errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in event-loop: %v", err)
}
}
}
Expand All @@ -134,25 +132,19 @@ func (p *Poller) Polling() error {
doChores = false
task := p.urgentAsyncTaskQueue.Dequeue()
for ; task != nil; task = p.urgentAsyncTaskQueue.Dequeue() {
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
for i := 0; i < MaxAsyncTasksAtOneTime; i++ {
if task = p.asyncTaskQueue.Dequeue(); task == nil {
break
}
switch err = task.Run(task.Arg); err {
case nil:
case errors.ErrEngineShutdown:
err = task.Run(task.Arg)
if errors.Is(err, errorx.ErrEngineShutdown) {
return err
default:
logging.Warnf("error occurs in user-defined function, %v", err)
}
queue.PutTask(task)
}
Expand Down
Loading