Skip to content

Commit

Permalink
Cherry picks for v2.10.20 (#5843)
Browse files Browse the repository at this point in the history
Includes:

- #5841 
- #5836
- #5837
  • Loading branch information
wallyqs authored Aug 29, 2024
2 parents e7c88e8 + 2b625ce commit a24fe36
Show file tree
Hide file tree
Showing 7 changed files with 90 additions and 45 deletions.
8 changes: 5 additions & 3 deletions .github/actions/nightly-release/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ runs:
go-version: "${{ inputs.go }}"

- name: goreleaser
uses: goreleaser/goreleaser-action@v5
# Use commit hash here to avoid a re-tagging attack, as this is a third-party action
# Commit 5742e2a039330cbb23ebf35f046f814d4c6ff811 = tag v5
uses: goreleaser/goreleaser-action@5742e2a039330cbb23ebf35f046f814d4c6ff811
with:
workdir: "${{ inputs.workdir }}"
version: latest
Expand All @@ -49,9 +51,9 @@ runs:
shell: bash
run: |
NDATE=$(date +%Y%m%d)
docker tag synadia/nats-server:nightly-${NDATE} synadia/nats-server:${{ inputs.label }}-${NDATE}
docker tag synadia/nats-server:nightly-${NDATE} synadia/nats-server:${{ inputs.label }}
docker push synadia/nats-server:${{ inputs.label }}-${NDATE}
docker push synadia/nats-server:${{ inputs.label }}
8 changes: 6 additions & 2 deletions .github/workflows/cov.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,17 @@ jobs:
set +e
- name: Convert coverage.out to coverage.lcov
uses: jandelgado/gcov2lcov-action@v1.0.9
# Use commit hash here to avoid a re-tagging attack, as this is a third-party action
# Commit c680c0f7c7442485f1749eb2a13e54a686e76eb5 = tag v1.0.9
uses: jandelgado/gcov2lcov-action@c680c0f7c7442485f1749eb2a13e54a686e76eb5
with:
infile: acc.out
working-directory: src/github.com/nats-io/nats-server

- name: Coveralls
uses: coverallsapp/github-action@v2
# Use commit hash here to avoid a re-tagging attack, as this is a third-party action
# Commit 3dfc5567390f6fa9267c0ee9c251e4c8c3f18949 = tag v2
uses: coverallsapp/github-action@3dfc5567390f6fa9267c0ee9c251e4c8c3f18949
with:
github-token: ${{ secrets.github_token }}
file: src/github.com/nats-io/nats-server/coverage.lcov
35 changes: 27 additions & 8 deletions server/certstore/certstore_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,19 +115,38 @@ var (
winMyStore = winWide("MY")

// These DLLs must be available on all Windows hosts
winCrypt32 = windows.MustLoadDLL("crypt32.dll")
winNCrypt = windows.MustLoadDLL("ncrypt.dll")
winCrypt32 = windows.NewLazySystemDLL("crypt32.dll")
winNCrypt = windows.NewLazySystemDLL("ncrypt.dll")

winCertFindCertificateInStore = winCrypt32.MustFindProc("CertFindCertificateInStore")
winCryptAcquireCertificatePrivateKey = winCrypt32.MustFindProc("CryptAcquireCertificatePrivateKey")
winNCryptExportKey = winNCrypt.MustFindProc("NCryptExportKey")
winNCryptOpenStorageProvider = winNCrypt.MustFindProc("NCryptOpenStorageProvider")
winNCryptGetProperty = winNCrypt.MustFindProc("NCryptGetProperty")
winNCryptSignHash = winNCrypt.MustFindProc("NCryptSignHash")
winCertFindCertificateInStore = winCrypt32.NewProc("CertFindCertificateInStore")
winCryptAcquireCertificatePrivateKey = winCrypt32.NewProc("CryptAcquireCertificatePrivateKey")
winNCryptExportKey = winNCrypt.NewProc("NCryptExportKey")
winNCryptOpenStorageProvider = winNCrypt.NewProc("NCryptOpenStorageProvider")
winNCryptGetProperty = winNCrypt.NewProc("NCryptGetProperty")
winNCryptSignHash = winNCrypt.NewProc("NCryptSignHash")

winFnGetProperty = winGetProperty
)

func init() {
for _, d := range []*windows.LazyDLL{
winCrypt32, winNCrypt,
} {
if err := d.Load(); err != nil {
panic(err)
}
}
for _, p := range []*windows.LazyProc{
winCertFindCertificateInStore, winCryptAcquireCertificatePrivateKey,
winNCryptExportKey, winNCryptOpenStorageProvider,
winNCryptGetProperty, winNCryptSignHash,
} {
if err := p.Find(); err != nil {
panic(err)
}
}
}

type winPKCS1PaddingInfo struct {
pszAlgID *uint16
}
Expand Down
39 changes: 19 additions & 20 deletions server/jetstream_cluster_4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2913,27 +2913,26 @@ func TestJetStreamClusterKeyValueLastSeqMismatch(t *testing.T) {
nc, js := jsClientConnect(t, c.randomServer())
defer nc.Close()

kv, err := js.CreateKeyValue(&nats.KeyValueConfig{
Bucket: "mismatch",
Replicas: 3,
})
require_NoError(t, err)

revision, err := kv.Create("foo", []byte("1"))
require_NoError(t, err)
require_Equal(t, revision, 1)
for _, r := range []int{1, 3} {
t.Run(fmt.Sprintf("R=%d", r), func(t *testing.T) {
kv, err := js.CreateKeyValue(&nats.KeyValueConfig{
Bucket: fmt.Sprintf("mismatch_%v", r),
Replicas: r,
})
require_NoError(t, err)

revision, err = kv.Create("bar", []byte("2"))
require_NoError(t, err)
require_Equal(t, revision, 2)
revision, err := kv.Create("foo", []byte("1"))
require_NoError(t, err)
require_Equal(t, revision, 1)

// Now delete foo from sequence 1.
// This needs to be low level remove (or system level) to test the condition we want here.
err = js.DeleteMsg("KV_mismatch", 1)
require_Error(t, err)
revision, err = kv.Create("bar", []byte("2"))
require_NoError(t, err)
require_Equal(t, revision, 2)

// Now say we want to update baz but iff last was revision 1.
_, err = kv.Update("baz", []byte("3"), uint64(1))
require_Error(t, err)
require_Equal(t, err.Error(), `nats: wrong last sequence: 0`)
// Now say we want to update baz but iff last was revision 1.
_, err = kv.Update("baz", []byte("3"), uint64(1))
require_Error(t, err)
require_Equal(t, err.Error(), `nats: wrong last sequence: 0`)
})
}
}
18 changes: 17 additions & 1 deletion server/pse/pse_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,33 @@ import (
"syscall"
"time"
"unsafe"

"golang.org/x/sys/windows"
)

var (
pdh = syscall.NewLazyDLL("pdh.dll")
pdh = windows.NewLazySystemDLL("pdh.dll")
winPdhOpenQuery = pdh.NewProc("PdhOpenQuery")
winPdhAddCounter = pdh.NewProc("PdhAddCounterW")
winPdhCollectQueryData = pdh.NewProc("PdhCollectQueryData")
winPdhGetFormattedCounterValue = pdh.NewProc("PdhGetFormattedCounterValue")
winPdhGetFormattedCounterArray = pdh.NewProc("PdhGetFormattedCounterArrayW")
)

func init() {
if err := pdh.Load(); err != nil {
panic(err)
}
for _, p := range []*windows.LazyProc{
winPdhOpenQuery, winPdhAddCounter, winPdhCollectQueryData,
winPdhGetFormattedCounterValue, winPdhGetFormattedCounterArray,
} {
if err := p.Find(); err != nil {
panic(err)
}
}
}

// global performance counter query handle and counters
var (
pcHandle PDH_HQUERY
Expand Down
2 changes: 1 addition & 1 deletion server/stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -4400,7 +4400,7 @@ func (mset *stream) processJetStreamMsg(subject, reply string, hdr, msg []byte,
if err == ErrStoreMsgNotFound {
if seq == 0 {
fseq, err = 0, nil
} else {
} else if mset.isClustered() {
// Do not bump clfs in case message was not found and could have been deleted.
var ss StreamState
store.FastState(&ss)
Expand Down
25 changes: 15 additions & 10 deletions server/sysmem/mem_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,23 @@
package sysmem

import (
"syscall"
"unsafe"

"golang.org/x/sys/windows"
)

var winKernel32 = windows.NewLazySystemDLL("kernel32.dll")
var winGlobalMemoryStatusEx = winKernel32.NewProc("GlobalMemoryStatusEx")

func init() {
if err := winKernel32.Load(); err != nil {
panic(err)
}
if err := winGlobalMemoryStatusEx.Find(); err != nil {
panic(err)
}
}

// https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/ns-sysinfoapi-memorystatusex
type _memoryStatusEx struct {
dwLength uint32
Expand All @@ -30,16 +43,8 @@ type _memoryStatusEx struct {
}

func Memory() int64 {
kernel32, err := syscall.LoadDLL("kernel32.dll")
if err != nil {
return 0
}
globalMemoryStatusEx, err := kernel32.FindProc("GlobalMemoryStatusEx")
if err != nil {
return 0
}
msx := &_memoryStatusEx{dwLength: 64}
res, _, _ := globalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msx)))
res, _, _ := winGlobalMemoryStatusEx.Call(uintptr(unsafe.Pointer(msx)))
if res == 0 {
return 0
}
Expand Down

0 comments on commit a24fe36

Please sign in to comment.