Skip to content

Commit

Permalink
Merge branch 'panjf2000:dev' into dev
Browse files Browse the repository at this point in the history
  • Loading branch information
0-haha authored Oct 14, 2024
2 parents e1a5a23 + ab70394 commit ee22f05
Show file tree
Hide file tree
Showing 30 changed files with 203 additions and 197 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/cross-compile-bsd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ jobs:
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.22']
go: ['1.20', '1.23']
os:
- ubuntu-latest
name: Go ${{ matrix.go }} @ ${{ matrix.os }}
Expand Down
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 }}
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.17'
go-version: '^1.20'
cache: false

- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2
version: v1.61.0
args: -v -E gofumpt -E gocritic -E misspell -E revive -E godot --timeout 5m
test:
needs: lint
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.22']
go: ['1.20', '1.23']
os:
- ubuntu-latest
- macos-latest
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/test_gc_opt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,20 +43,20 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.17'
go-version: '^1.20'
cache: false

- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2
version: v1.61.0
args: -v -E gofumpt -E gocritic -E misspell -E revive -E godot --timeout 5m
test:
needs: lint
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.22']
go: ['1.20', '1.23']
os:
- ubuntu-latest
- macos-latest
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test_poll_opt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.17'
go-version: '^1.20'
cache: false

- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2
version: v1.61.0
args: -v -E gofumpt -E gocritic -E misspell -E revive -E godot
test:
needs: lint
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.22']
go: ['1.20', '1.23']
os: [ubuntu-latest, macos-latest]
name: Go ${{ matrix.go }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -68,7 +68,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.17'
go-version: '^1.20'

- name: Print Go environment
id: go-env
Expand Down
10 changes: 5 additions & 5 deletions .github/workflows/test_poll_opt_gc_opt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,20 +42,20 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.17'
go-version: '^1.20'
cache: false

- name: Setup and run golangci-lint
uses: golangci/golangci-lint-action@v4
uses: golangci/golangci-lint-action@v6
with:
version: v1.56.2
version: v1.61.0
args: -v -E gofumpt -E gocritic -E misspell -E revive -E godot
test:
needs: lint
strategy:
fail-fast: false
matrix:
go: ['1.17', '1.22']
go: ['1.20', '1.23']
os: [ubuntu-latest, macos-latest]
name: Go ${{ matrix.go }} @ ${{ matrix.os }}
runs-on: ${{ matrix.os }}
Expand All @@ -68,7 +68,7 @@ jobs:
- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: '^1.17'
go-version: '^1.20'

- name: Print Go environment
id: go-env
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a title="Build Status" target="_blank" href="https://github.com/panjf2000/gnet/actions?query=workflow%3ATests"><img src="https://img.shields.io/github/actions/workflow/status/panjf2000/gnet/test.yml?branch=dev&style=flat-square&logo=github-actions" /></a>
<a title="Codecov" target="_blank" href="https://codecov.io/gh/panjf2000/gnet"><img src="https://img.shields.io/codecov/c/github/panjf2000/gnet?style=flat-square&logo=codecov" /></a>
<a title="Supported Platforms" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/platform-Linux%20%7C%20macOS%20%7C%20*BSD%20%7C%20Windows-549688?style=flat-square&logo=launchpad" /></a>
<a title="Require Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.17-30dff3?style=flat-square&logo=go" /></a>
<a title="Minimum Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.20-30dff3?style=flat-square&logo=go" /></a>
<br />
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/panjf2000/gnet"><img src="https://goreportcard.com/badge/github.com/panjf2000/gnet?style=flat-square" /></a>
<a title="Doc for gnet" target="_blank" href="https://pkg.go.dev/github.com/panjf2000/gnet/v2#section-documentation"><img src="https://img.shields.io/badge/go.dev-doc-007d9c?style=flat-square&logo=read-the-docs" /></a>
Expand Down 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
6 changes: 3 additions & 3 deletions README_ZH.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<a title="Build Status" target="_blank" href="https://github.com/panjf2000/gnet/actions?query=workflow%3ATests"><img src="https://img.shields.io/github/actions/workflow/status/panjf2000/gnet/test.yml?branch=dev&style=flat-square&logo=github-actions" /></a>
<a title="Codecov" target="_blank" href="https://codecov.io/gh/panjf2000/gnet"><img src="https://img.shields.io/codecov/c/github/panjf2000/gnet?style=flat-square&logo=codecov" /></a>
<a title="Supported Platforms" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/platform-Linux%20%7C%20macOS%20%7C%20*BSD%20%7C%20Windows-549688?style=flat-square&logo=launchpad" /></a>
<a title="Require Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.17-30dff3?style=flat-square&logo=go" /></a>
<a title="Minimum Go Version" target="_blank" href="https://github.com/panjf2000/gnet"><img src="https://img.shields.io/badge/go-%3E%3D1.20-30dff3?style=flat-square&logo=go" /></a>
<br />
<a title="Go Report Card" target="_blank" href="https://goreportcard.com/report/github.com/panjf2000/gnet"><img src="https://goreportcard.com/badge/github.com/panjf2000/gnet?style=flat-square" /></a>
<a title="Doc for gnet" target="_blank" href="https://pkg.go.dev/github.com/panjf2000/gnet/v2#section-documentation"><img src="https://img.shields.io/badge/go.dev-doc-007d9c?style=flat-square&logo=read-the-docs" /></a>
Expand Down 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
4 changes: 2 additions & 2 deletions client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ package gnet

import (
"bytes"
crand "crypto/rand"
"io"
"math/rand"
"net"
Expand Down Expand Up @@ -462,7 +463,6 @@ func runClient(t *testing.T, network, addr string, et, reuseport, multicore, asy
}

func startGnetClient(t *testing.T, cli *Client, network, addr string, multicore, async, netDial bool) {
rand.Seed(time.Now().UnixNano())
var (
c Conn
err error
Expand Down Expand Up @@ -492,7 +492,7 @@ func startGnetClient(t *testing.T, cli *Client, network, addr string, multicore,
if network == "udp" {
reqData = reqData[:datagramLen]
}
_, err = rand.Read(reqData)
_, err = crand.Read(reqData)
require.NoError(t, err)
err = c.AsyncWrite(reqData, nil)
require.NoError(t, err)
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
2 changes: 1 addition & 1 deletion eventloop_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ func (el *eventloop) ticker(ctx context.Context) {
for {
delay, action = el.eventHandler.OnTick()
switch action {
case None:
case None, Close:
case Shutdown:
// It seems reasonable to mark this as low-priority, waiting for some tasks like asynchronous writes
// to finish up before shutting down the service.
Expand Down
2 changes: 1 addition & 1 deletion eventloop_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ func (s *testServerGC) GC(secs int) {
runtime.GC()
gcTime := time.Since(now)
gcAllTime += gcTime
s.tester.Log(s.tester.Name(), s.network, " server gc:", gcTime, ", average gc time:", gcAllTime/gcAllCount)
s.tester.Log(s.tester.Name(), s.network, "server gc:", gcTime, "average gc time:", gcAllTime/gcAllCount)
if time.Since(gcStart) >= time.Second*time.Duration(secs) {
break
}
Expand Down
2 changes: 1 addition & 1 deletion eventloop_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (el *eventloop) ticker(ctx context.Context) {
for {
delay, action = el.eventHandler.OnTick()
switch action {
case None:
case None, Close:
case Shutdown:
if !shutdown {
shutdown = true
Expand Down
2 changes: 0 additions & 2 deletions gnet.go
Original file line number Diff line number Diff line change
Expand Up @@ -293,8 +293,6 @@ type Socket interface {
// algorithm).
// The default is true (no delay), meaning that data is sent as soon as possible after a Write.
SetNoDelay(noDelay bool) error
// CloseRead() error
// CloseWrite() error
}

// Conn is an interface of underlying connection.
Expand Down
Loading

0 comments on commit ee22f05

Please sign in to comment.