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

Lev micro stops when server stops dev #113

Draft
wants to merge 39 commits into
base: lev-micro-stops-when-server-stops
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
4444714
TRY MORE
levb Nov 2, 2024
b832eab
TRY MORE, .github
levb Nov 2, 2024
ea714ca
TRY MORE, logs for MicroServiceStopsOnClosedConn
levb Nov 2, 2024
6344935
TRY MORE, +1
levb Nov 3, 2024
e8be798
TRY MORE, +2
levb Nov 3, 2024
c66c264
TRY MORE, +3
levb Nov 3, 2024
aad38a8
TRY MORE, +4
levb Nov 3, 2024
cef4f74
TRY MORE, +5
levb Nov 3, 2024
f4122ed
TRY MORE, +6
levb Nov 3, 2024
ba8a793
TRY MORE, +7
levb Nov 3, 2024
0ada368
TRY MORE, +8
levb Nov 3, 2024
c2e2e2f
TRY MORE, +9
levb Nov 3, 2024
abb09e6
TRY MORE, +10
levb Nov 3, 2024
dea759e
TRY MORE, +11
levb Nov 3, 2024
1fcbe70
TRY MORE, +12
levb Nov 3, 2024
7fe1a46
TRY MORE, +13
levb Nov 3, 2024
a00c077
TRY MORE, +14
levb Nov 3, 2024
7d118e4
TRY MORE, +15
levb Nov 3, 2024
96d655e
TRY MORE, +16
levb Nov 3, 2024
176899f
TRY MORE, +17
levb Nov 3, 2024
a69c417
TRY MORE, +18
levb Nov 3, 2024
5538d70
TRY MORE, +19 fixed MicroBasics
levb Nov 3, 2024
de7564f
TRY MORE, +20
levb Nov 3, 2024
a18e070
TRY MORE, chase slowness
levb Nov 3, 2024
eca1191
TRY MORE, found?
levb Nov 3, 2024
0390c26
TRY MORE, +1
levb Nov 3, 2024
6a883d3
TRY MORE, +2
levb Nov 3, 2024
a68eb80
TRY MORE, +3
levb Nov 3, 2024
335b7e3
TRY MORE, +4
levb Nov 3, 2024
d565761
TRY MORE, +5
levb Nov 3, 2024
c811a80
cleanup
levb Nov 3, 2024
9df3d27
servicesMu
levb Nov 3, 2024
2ae33a2
adjustments
levb Nov 3, 2024
05cf5b4
adjustments, +1
levb Nov 3, 2024
1562929
adjustments, +2, longer sleep
levb Nov 3, 2024
541e2ea
adjustments, +2, no sleep, but mark as stopped before the callback
levb Nov 3, 2024
11be61c
adjustments, +3
levb Nov 3, 2024
c173957
adjustments, +4, removed sub=NULL hack
levb Nov 4, 2024
e430291
adjustments, +5
levb Nov 4, 2024
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
3 changes: 2 additions & 1 deletion .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ jobs:
export PATH=../deps/nats-server:../deps/nats-streaming-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
flags=""
ctest -L 'test' --timeout 60 --output-on-failure --repeat-until-fail ${{ inputs.repeat }}
ctest -R 'Micro' --timeout 60 --output-on-failure --repeat-until-fail 100
# ctest -L 'test' --timeout 60 --output-on-failure --repeat-until-fail ${{ inputs.repeat }}

- name: Upload coverage reports to Codecov
# PRs from external contributors fail: https://github.com/codecov/feedback/issues/301
Expand Down
162 changes: 81 additions & 81 deletions .github/workflows/on-pr-debug.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,90 +64,90 @@ jobs:
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

coverage-NO-verify_host:
name: "Coverage: NO-verify_host"
uses: ./.github/workflows/build-test.yml
with:
coverage: ON
type: RelWithDebInfo
server_version: main
compiler: gcc
tls: TLS
verify_host: NO-verify_host
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# coverage-NO-verify_host:
# name: "Coverage: NO-verify_host"
# uses: ./.github/workflows/build-test.yml
# with:
# coverage: ON
# type: RelWithDebInfo
# server_version: main
# compiler: gcc
# tls: TLS
# verify_host: NO-verify_host
# secrets:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

coverage-NO-TLS:
name: "Coverage NO-TLS"
uses: ./.github/workflows/build-test.yml
with:
coverage: ON
type: RelWithDebInfo
server_version: main
compiler: gcc
tls: NO-TLS
verify_host: NO-verify_host
secrets:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
# coverage-NO-TLS:
# name: "Coverage NO-TLS"
# uses: ./.github/workflows/build-test.yml
# with:
# coverage: ON
# type: RelWithDebInfo
# server_version: main
# compiler: gcc
# tls: NO-TLS
# verify_host: NO-verify_host
# secrets:
# CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}

bench:
name: "Benchmark"
uses: ./.github/workflows/build-test.yml
with:
server_version: main
benchmark: ON
type: Release
# bench:
# name: "Benchmark"
# uses: ./.github/workflows/build-test.yml
# with:
# server_version: main
# benchmark: ON
# type: Release

Windows:
name: "Windows"
runs-on: windows-latest
steps:
- name: Export GitHub Actions cache environment variables
uses: actions/github-script@v7
with:
script: |
core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');
# Windows:
# name: "Windows"
# runs-on: windows-latest
# steps:
# - name: Export GitHub Actions cache environment variables
# uses: actions/github-script@v7
# with:
# script: |
# core.exportVariable('ACTIONS_CACHE_URL', process.env.ACTIONS_CACHE_URL || '');
# core.exportVariable('ACTIONS_RUNTIME_TOKEN', process.env.ACTIONS_RUNTIME_TOKEN || '');

- name: Checkout nats.c
uses: actions/checkout@v4
# - name: Checkout nats.c
# uses: actions/checkout@v4

- name: Build
env:
VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
run: |
cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug -DNATS_BUILD_STREAMING=OFF
cmake --build build
# - name: Build
# env:
# VCPKG_BINARY_SOURCES: "clear;x-gha,readwrite"
# run: |
# cmake -B build -S . -DCMAKE_BUILD_TYPE=Debug -DNATS_BUILD_STREAMING=OFF
# cmake --build build

- name: Test
shell: bash
run: |
cd build
# Download latest nats-server
rel="latest" # TODO: parameterize
if [ "$rel" = "latest" ]; then
rel=$(curl -s https://api.github.com/repos/nats-io/nats-server/releases/latest | jq -r '.tag_name')
fi
if [ "$rel" != "${rel#v}" ] && wget https://github.com/nats-io/nats-server/releases/download/$rel/nats-server-$rel-windows-amd64.tar.gz; then
tar -xzf nats-server-$rel-linux-amd64.tar.gz
cp nats-server-$rel-windows-amd64/nats-server.exe ../deps/nats-server/nats-server.exe
else
for c in 1 2 3 4 5
do
echo "Attempt $c to download binary for main"
rm -f ./nats-server
curl -sf "https://binaries.nats.dev/nats-io/nats-server/v2@$rel" | PREFIX=. sh
# We are sometimes getting nats-server of size 0. Make sure we have a
# working nats-server by making sure we get a version number.
mv ./nats-server ./nats-server.exe
v="$(./nats-server.exe -v)"
if [ "$v" != "" ]; then
break
fi
done
mkdir -p ../deps/nats-server
mv ./nats-server.exe ../deps/nats-server/nats-server.exe
fi
export PATH=../deps/nats-server:$PATH
export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
ctest -L test -C Debug --timeout 60 --output-on-failure --repeat until-pass:3
# - name: Test
# shell: bash
# run: |
# cd build
# # Download latest nats-server
# rel="latest" # TODO: parameterize
# if [ "$rel" = "latest" ]; then
# rel=$(curl -s https://api.github.com/repos/nats-io/nats-server/releases/latest | jq -r '.tag_name')
# fi
# if [ "$rel" != "${rel#v}" ] && wget https://github.com/nats-io/nats-server/releases/download/$rel/nats-server-$rel-windows-amd64.tar.gz; then
# tar -xzf nats-server-$rel-linux-amd64.tar.gz
# cp nats-server-$rel-windows-amd64/nats-server.exe ../deps/nats-server/nats-server.exe
# else
# for c in 1 2 3 4 5
# do
# echo "Attempt $c to download binary for main"
# rm -f ./nats-server
# curl -sf "https://binaries.nats.dev/nats-io/nats-server/v2@$rel" | PREFIX=. sh
# # We are sometimes getting nats-server of size 0. Make sure we have a
# # working nats-server by making sure we get a version number.
# mv ./nats-server ./nats-server.exe
# v="$(./nats-server.exe -v)"
# if [ "$v" != "" ]; then
# break
# fi
# done
# mkdir -p ../deps/nats-server
# mv ./nats-server.exe ../deps/nats-server/nats-server.exe
# fi
# export PATH=../deps/nats-server:$PATH
# export NATS_TEST_SERVER_VERSION="$(nats-server -v)"
# ctest -L test -C Debug --timeout 60 --output-on-failure --repeat until-pass:3
1 change: 1 addition & 0 deletions .github/workflows/on-push-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ jobs:
server_version: main
ubuntu_version: ${{ matrix.ubuntu_version }}
compiler: ${{ matrix.compiler }}
type: RelWithDebInfo
69 changes: 3 additions & 66 deletions src/conn.c
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ _freeConn(natsConnection *nc)
natsStrHash_Destroy(nc->respMap);
natsCondition_Destroy(nc->reconnectCond);
natsMutex_Destroy(nc->subsMu);
natsMutex_Destroy(nc->servicesMu);
natsMutex_Destroy(nc->mu);
NATS_FREE(nc->services);

Expand Down Expand Up @@ -3239,6 +3240,8 @@ natsConn_create(natsConnection **newConn, natsOptions *options)
s = natsMutex_Create(&(nc->mu));
if (s == NATS_OK)
s = natsMutex_Create(&(nc->subsMu));
if (s == NATS_OK)
s = natsMutex_Create(&(nc->servicesMu));
if (s == NATS_OK)
s = _setupServerPool(nc);
if (s == NATS_OK)
Expand Down Expand Up @@ -4467,69 +4470,3 @@ natsConn_defaultErrHandler(natsConnection *nc, natsSubscription *sub, natsStatus
}
fflush(stderr);
}

int natsConn_getServices(microService ***services, natsConnection *nc)
{
int numServices = 0;
natsConn_Lock(nc);
*services = nc->services;
numServices = nc->numServices;
natsConn_Unlock(nc);
return numServices;
}

bool natsConn_removeService(natsConnection *nc, microService *service)
{
bool removed = false;
if (nc == NULL || service == NULL)
return false;

natsConn_Lock(nc);
for (int i = 0; i < nc->numServices; i++)
{
if (nc->services[i] == service)
{
for (int j = i; j < nc->numServices - 1; j++)
{
nc->services[j] = nc->services[j + 1];
}
nc->numServices--;
removed = true;
break;
}
}
natsConn_Unlock(nc);
return removed;
}

natsStatus natsConn_addService(natsConnection *nc, microService *service)
{
natsStatus s = NATS_OK;
if (nc == NULL || service == NULL)
return nats_setDefaultError(NATS_INVALID_ARG);

natsConn_Lock(nc);
if (nc->services == NULL)
{
nc->services = NATS_CALLOC(1, sizeof(microService *));
if (nc->services == NULL)
s = nats_setDefaultError(NATS_NO_MEMORY);
}
else
{
microService **tmp = NATS_REALLOC(nc->services, (nc->numServices + 1) * sizeof(microService *));
if (tmp == NULL)
s = nats_setDefaultError(NATS_NO_MEMORY);
else
nc->services = tmp;
}

if (s == NATS_OK)
{
nc->services[nc->numServices] = service;
nc->numServices++;
}
natsConn_Unlock(nc);

return s;
}
9 changes: 0 additions & 9 deletions src/conn.h
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,4 @@ natsConn_close(natsConnection *nc);
void
natsConn_destroy(natsConnection *nc, bool fromPublicDestroy);

int
natsConn_getServices(microService ***services, natsConnection *nc);

bool
natsConn_removeService(natsConnection *nc, microService *service);

natsStatus
natsConn_addService(natsConnection *nc, microService *service);

#endif /* CONN_H_ */
Loading