Skip to content
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
31 changes: 10 additions & 21 deletions .github/workflows/pre_check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,41 +4,30 @@

jobs:
compliant:
runs-on: [ self-hosted, X64 ]
runs-on: [ self-hosted, X64, Linux ]
steps:
- uses: actions/checkout@v3

- name: Check License Header
uses: apache/skywalking-eyes/header@v0.4.0
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Check Spell
uses: crate-ci/typos@v1.13.14

staticcheck:
runs-on: [ self-hosted, X64 ]
# 用一个新的、更强大的 linter 作业替换 staticcheck
linter:
runs-on: [ self-hosted, X64, Linux ]
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: 1.19

- uses: actions/cache@v3
with:
path: ~/go/pkg/mod
key: reviewdog-${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
restore-keys: |
reviewdog-${{ runner.os }}-go-
- uses: reviewdog/action-staticcheck@v1
go-version: "1.20"
- name: Run golangci-lint
# 使用官方的 golangci-lint-action
uses: golangci/golangci-lint-action@v8
with:
github_token: ${{ secrets.github_token }}
# Change reviewdog reporter if you need [github-pr-check,github-check,github-pr-review].
reporter: github-pr-review
# Report all results.
filter_mode: added
# Exit with 1 when it find at least one finding.
fail_on_error: true
# Set staticcheck flags
staticcheck_flags: -checks=inherit,-SA1029,-SA2002,-SA4006,-SA2002,-SA9003,-S1024 -exclude=example
# 指定要使用的 golangci-lint 版本
version: v2.5
13 changes: 8 additions & 5 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,37 @@
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.17'
go-version: '1.20'
- name: Unit Test
run: go test -gcflags=-l -covermode=atomic -coverprofile=coverage.txt
- name: Codecov
run: bash <(curl -s https://codecov.io/bash)

benchmark-test:
needs: unit-scenario-test
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: '1.17'
go-version: '1.20'
- name: Benchmark
run: go test -gcflags='all=-N -l' -bench=. -benchmem -run=none

compatibility-test:

Check warning

Code scanning / CodeQL

Workflow does not contain permissions Medium test

Actions job or workflow does not limit the permissions of the GITHUB_TOKEN. Consider setting an explicit permissions block, using the following as a minimal starting point: {contents: read}
needs: benchmark-test
strategy:
max-parallel: 1
matrix:
go: [1.13, 1.14, 1.15, 1.16, 1.18, 1.19, "1.20" ]
go: [ 1.21, 1.22, 1.23, 1.24, 1.25 ]
os: [ X64 ]
runs-on: ${{ matrix.os }}
runs-on: [ Linux, '${{ matrix.os }}' ]
steps:
- uses: actions/checkout@v3
- name: Set up Go
uses: actions/setup-go@v3
with:
go-version: ${{ matrix.go }}
- name: Unit Test
run: go test -gcflags=-l -covermode=atomic
run: go test -gcflags=-l -covermode=atomic
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
.idea
coverage.txt
35 changes: 35 additions & 0 deletions .golangci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
# .golangci.yml
run:
timeout: 5m

linters:
enable:
- staticcheck
- govet
- ineffassign
disable:
- errcheck
- unused
exclusions:
paths:
- '(.+)_test\.go'
- 'example'
settings:
staticcheck:
checks:
- all
- '-SA1029'
- '-SA2002'
- '-SA4006'
- '-SA2002'
- '-SA9003'
- '-S1024'
- '-ST1000'
- '-QF1008'
- '-SA1019'
- '-QF1011'
- '-ST1003'
- '-QF1001'
- '-ST1020'

version: '2'
2 changes: 1 addition & 1 deletion bench_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package shmipc

import (
"fmt"
syscall "golang.org/x/sys/unix"
"io"
"math/rand"
"net"
"net/http"
_ "net/http/pprof"
"strconv"
"syscall"
"testing"
"time"
)
Expand Down
2 changes: 1 addition & 1 deletion block_io.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ package shmipc

import (
"fmt"
syscall "golang.org/x/sys/unix"
"io"
"syscall"
)

func blockReadFull(connFd int, data []byte) error {
Expand Down
4 changes: 3 additions & 1 deletion buffer.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import (
"sync"
"sync/atomic"
"unsafe"

"github.com/bytedance/gopkg/lang/dirtmake"
)

var (
Expand Down Expand Up @@ -333,7 +335,7 @@ func (l *linkedBuffer) ReadBytes(size int) (result []byte, err error) {
}
// slow path
l.len -= size
result = make([]byte, 0, size)
result = dirtmake.Bytes(0, size)

for size > 0 {
readData, _ := l.sliceList.front().read(size)
Expand Down
2 changes: 1 addition & 1 deletion buffer_manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ package shmipc
import (
"errors"
"fmt"
syscall "golang.org/x/sys/unix"
"os"
"path/filepath"
"sort"
"sync"
"sync/atomic"
"syscall"
"time"
"unsafe"
)
Expand Down
20 changes: 10 additions & 10 deletions debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ func init() {
}
}

//SetLogLevel used to change the internal logger's level and the default level is Warning.
//The process env `SHMIPC_LOG_LEVEL` also could set log level
// SetLogLevel used to change the internal logger's level and the default level is Warning.
// The process env `SHMIPC_LOG_LEVEL` also could set log level
func SetLogLevel(l int) {
if l <= levelNoPrint {
level = l
Expand Down Expand Up @@ -229,15 +229,15 @@ func computeFreeSliceNum(list *bufferList) int {
return freeSlices
}

//1.occurred memory leak, if list's free slice number != expect free slice number.
//2.print the metadata and payload of the leaked slice.
// 1.occurred memory leak, if list's free slice number != expect free slice number.
// 2.print the metadata and payload of the leaked slice.
func debugBufferListDetail(path string, bufferMgrHeaderSize int, bufferHeaderSize int) {
mem, err := ioutil.ReadFile(path)
if err != nil {
fmt.Println(err)
return
}
bm, err := mappingBufferManager(path, mem, 0)
bm, _ := mappingBufferManager(path, mem, 0)
expectAllSliceNum := uint32(0)
for i, list := range bm.lists {
fmt.Printf("%d. list capacity:%d size:%d realSize:%d perSliceCap:%d headOffset:%d tailOffset:%d\n",
Expand Down Expand Up @@ -276,15 +276,15 @@ func printLeakShareMemory(bm *bufferManager, bufferMgrHeaderSize int, bufferHead
}
}

//DebugBufferListDetail print all BufferList's status in share memory located in the `path`
//if MemMapType is MemMapTypeMemFd, you could using the command that
//`lsof -p $PID` to found the share memory which was mmap by memfd,
//and the command `cat /proc/$PID/$MEMFD > $path` dump the share memory to file system.
// DebugBufferListDetail print all BufferList's status in share memory located in the `path`
// if MemMapType is MemMapTypeMemFd, you could using the command that
// `lsof -p $PID` to found the share memory which was mmap by memfd,
// and the command `cat /proc/$PID/$MEMFD > $path` dump the share memory to file system.
func DebugBufferListDetail(path string) {
debugBufferListDetail(path, 8, 20)
}

//DebugQueueDetail print IO-Queue's status which was mmap in the `path`
// DebugQueueDetail print IO-Queue's status which was mmap in the `path`
func DebugQueueDetail(path string) {
mem, err := ioutil.ReadFile(path)
if err != nil {
Expand Down
6 changes: 4 additions & 2 deletions epoll_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !arm64
// +build !arm64

/*
Expand All @@ -19,11 +20,12 @@
package shmipc

import (
"syscall"
syscall "golang.org/x/sys/unix"

"unsafe"
)

const epollModeET = -syscall.EPOLLET
const epollModeET = syscall.EPOLLET

type epollEvent struct {
events uint32
Expand Down
2 changes: 1 addition & 1 deletion epoll_linux_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
package shmipc

import (
"syscall"
syscall "golang.org/x/sys/unix"
"unsafe"
)

Expand Down
8 changes: 5 additions & 3 deletions event_dispatcher_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !race
// +build !race

/*
Expand All @@ -20,11 +21,11 @@ package shmipc

import (
"fmt"
syscall "golang.org/x/sys/unix"
"os"
"runtime"
"sync"
"sync/atomic"
"syscall"
"unsafe"
)

Expand Down Expand Up @@ -74,7 +75,7 @@ func (c *connEventHandler) onRemoteClose() {
c.deferredClose()
}

//avoiding write concurrently, blocking until return
// avoiding write concurrently, blocking until return
func (c *connEventHandler) writev(data ...[]byte) error {
if len(data) == 0 {
return nil
Expand Down Expand Up @@ -135,7 +136,7 @@ func (c *connEventHandler) doWritev(data ...[]byte) (int, error) {
return writtenSliceNum, nil
}

//avoiding write concurrently, blocking until return
// avoiding write concurrently, blocking until return
func (c *connEventHandler) write(data []byte) error {
written, size := 0, len(data)
for written < size {
Expand Down Expand Up @@ -344,6 +345,7 @@ func (d *epollDispatcher) runLoop() error {
d.lock.Unlock()
d.runLambda()
}
//nolint:govet
runtime.KeepAlive(d)
}()
return nil
Expand Down
7 changes: 4 additions & 3 deletions event_dispatcher_race_linux.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build race
// +build race

/*
Expand All @@ -21,11 +22,11 @@ package shmipc
import (
"encoding/binary"
"fmt"
syscall "golang.org/x/sys/unix"
"os"
"runtime"
"sync"
"sync/atomic"
"syscall"
"unsafe"
)

Expand Down Expand Up @@ -75,7 +76,7 @@ func (c *connEventHandler) onRemoteClose() {
c.deferredClose()
}

//avoiding write concurrently, blocking until return
// avoiding write concurrently, blocking until return
func (c *connEventHandler) writev(data ...[]byte) error {
if len(data) == 0 {
return nil
Expand Down Expand Up @@ -136,7 +137,7 @@ func (c *connEventHandler) doWritev(data ...[]byte) (int, error) {
return writtenSliceNum, nil
}

//avoiding write concurrently, blocking until return
// avoiding write concurrently, blocking until return
func (c *connEventHandler) write(data []byte) error {
written, size := 0, len(data)
for written < size {
Expand Down
4 changes: 2 additions & 2 deletions example/best_practice/net_server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ package main

import (
"fmt"
syscall "golang.org/x/sys/unix"
"net"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"runtime"
"sync/atomic"
"syscall"
"time"

"github.com/cloudwego/shmipc-go/example/best_practice/idl"
Expand Down Expand Up @@ -77,7 +77,7 @@ func init() {
}
}()
go func() {
http.ListenAndServe(":20000", nil)//nolint:errcheck
http.ListenAndServe(":20000", nil) //nolint:errcheck
}()
runtime.GOMAXPROCS(1)
}
Expand Down
4 changes: 2 additions & 2 deletions example/best_practice/shmipc_async_server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ package main

import (
"fmt"
syscall "golang.org/x/sys/unix"
"net/http"
_ "net/http/pprof"
"os"
"path/filepath"
"runtime"
"sync/atomic"
"syscall"
"time"

"github.com/cloudwego/shmipc-go"
Expand Down Expand Up @@ -102,7 +102,7 @@ func init() {
runtime.GOMAXPROCS(1)

go func() {
http.ListenAndServe(":20000", nil)//nolint:errcheck
http.ListenAndServe(":20000", nil) //nolint:errcheck
}()
}

Expand Down
Loading
Loading