Skip to content

Improve remote shell loop error handling - #851

Open
pnoltes wants to merge 9 commits into
masterfrom
feature/improve-remote-shell-loop-handling
Open

pnoltes wants to merge 9 commits into
masterfrom
feature/improve-remote-shell-loop-handling

Conversation

@pnoltes

@pnoltes pnoltes commented Sep 27, 2026

Copy link
Copy Markdown
Contributor

Improve remote shell loop by recv return and then logging result and exiting loop if needed.

@codecov-commenter

codecov-commenter commented Sep 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 59.25926% with 66 lines in your changes missing coverage. Please review.
✅ Project coverage is 91.68%. Comparing base (270c784) to head (f80c68e).
⚠️ Report is 3 commits behind head on master.

Files with missing lines Patch % Lines
...e_service_admin_dfi/src/remote_service_admin_dfi.c 59.37% 39 Missing ⚠️
bundles/http_admin/http_admin/src/http_admin.c 59.09% 27 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #851      +/-   ##
==========================================
+ Coverage   91.54%   91.68%   +0.13%     
==========================================
  Files         235      235              
  Lines       28787    28980     +193     
==========================================
+ Hits        26353    26570     +217     
+ Misses       2434     2410      -24     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@PengZheng PengZheng left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Though networking bundles are not robust enough to be used in production environment, they are still instructive to help programmers learn how to integrate Celix. It's OK that we add some basic protections first before a refactoring.

@PengZheng PengZheng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice improvement for our networking code.
The HTTP code is good enough except for its zero return handling.
The TCP part is more difficult to deal with raw socket API.

@PengZheng PengZheng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left some further remarks, some of which need to be addressed before merging this PR.

for (i = 0; i < length; i += 1) {
connection_pt connection = celix_arrayList_get(instance->connections, i);
connection->threadRunning = false;
connection_setThreadRunning(connection, false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have found no synchronization between connection processing thread and the calling thread, and thus suspect use-after-free bugs here.
Moreover, we never calling pthread_join on these connection processing thread, these are definitely resource leaks.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pthread_join added

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remoteShell_stopConnections is only invoked when bundle stops, thus the resources used by these threads will only be released then. If new connection keeps coming, the overall resource usage will increase monotonically. Kind of resource leak. @pnoltes

@PengZheng PengZheng left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have left some further remarks.

}
totalBytesRead += (size_t)read;
}
if (contentLength > 0 && totalBytesRead < (size_t)contentLength) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If fclose(celix_streal_ptr(stream)) before this, could we replace memSize by totalBytesRead so that we can also drop totalBytesRead += (size_t)read? Of cource we need to fflush the stream after fwrite to get totalBytesRead updated.

return 400;
}
}
*bufferOut = celix_steal_ptr(buffer);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Note that buffer could be changed (and thus made invalid AND obsolete) by the final implicit fclose.

for (i = 0; i < length; i += 1) {
connection_pt connection = celix_arrayList_get(instance->connections, i);
connection->threadRunning = false;
connection_setThreadRunning(connection, false);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remoteShell_stopConnections is only invoked when bundle stops, thus the resources used by these threads will only be released then. If new connection keeps coming, the overall resource usage will increase monotonically. Kind of resource leak. @pnoltes

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants