Skip to content

go-exec/module: Run the prompts callbacks in the main thread - #1734

Open
3v1n0 wants to merge 9 commits into
canonical:mainfrom
3v1n0:run-prompts-in-action-context
Open

go-exec/module: Run the prompts callbacks in the main thread#1734
3v1n0 wants to merge 9 commits into
canonical:mainfrom
3v1n0:run-prompts-in-action-context

Conversation

@3v1n0

@3v1n0 3v1n0 commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

pam_prompt leads to calling code into the caller application, and doing this in a different thread may be unsafe.

So run a separated context/loop in the main thread and use it to call code that should run in the main thread

Superseeds #1726 (/cc @adombeck)

UDENG-11102

@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch 3 times, most recently from 8332d25 to 862f177 Compare July 15, 2026 09:57
@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch 3 times, most recently from 9ec17bf to 9e4cbfb Compare July 15, 2026 10:08
@3v1n0 3v1n0 added the e2e-tests This issue is related to end-to-end tests / Run end-to-end tests on this pull request label Jul 15, 2026
@3v1n0
3v1n0 requested a review from Copilot July 15, 2026 18:08

Copilot AI 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.

Pull request overview

This PR updates the pam/go-exec PAM module to ensure PAM conversation callbacks (notably pam_prompt() and pam_error()) are executed on the calling thread by running a dedicated GMainContext/GMainLoop in that thread and dispatching the prompt/error work onto it. This addresses thread-safety issues and avoids deadlocks in callers that expect conversation callbacks to run on their own thread (e.g., Qt-based PAM workers).

Changes:

  • Introduces a per-call “action context” main loop in the calling thread and uses g_main_context_invoke_full() to run pam_prompt()/pam_error() on that thread.
  • Refactors state to carry pam_handle_t * and the new action_context in ActionData (instead of ModuleData) to support cross-thread invocation safely.
  • Adjusts D-Bus Prompt handling to return asynchronously once the main-thread prompt completes.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread pam/go-exec/module.c Outdated
@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch from 9e4cbfb to 914b03a Compare July 15, 2026 21:55
@3v1n0
3v1n0 requested a review from Copilot July 15, 2026 22:04

Copilot AI 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.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.

Comment thread pam/go-exec/module.c Outdated
Comment thread pam/go-exec/module.c
@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch 7 times, most recently from a08cbd7 to da936bf Compare July 22, 2026 15:31
@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch from da936bf to 11dea4f Compare July 24, 2026 21:15
@codecov

codecov Bot commented Jul 24, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.42373% with 29 lines in your changes missing coverage. Please review.
✅ Project coverage is 87.94%. Comparing base (72e9eaf) to head (1ecdbdb).
⚠️ Report is 5 commits behind head on main.

Files with missing lines Patch % Lines
pam/go-exec/module.c 75.42% 15 Missing and 14 partials ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1734      +/-   ##
==========================================
- Coverage   88.01%   87.94%   -0.07%     
==========================================
  Files          96       96              
  Lines        7016     7093      +77     
  Branches      112      128      +16     
==========================================
+ Hits         6175     6238      +63     
- Misses        785      786       +1     
- Partials       56       69      +13     

☔ 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.

@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch from 11dea4f to 28788b5 Compare July 24, 2026 21:29
3v1n0 added 5 commits July 24, 2026 23:34
pam_prompt leads to calling code into the caller application, and doing
this in a different thread may be unsafe.

So run a separated context/loop in the main thread and use it to call
code that should run in the main thread
While it's a per-module information there's no need to save it there
since it's something that will be available for each action, and this
would allow further simplifications
We may want to notify this in the main thread too, so let's prepare the
code for that
pam_error implies calling conversation functions in the calling
application, so do it in the same thread.
While this is not fully required because
g_dbus_method_invocation_return_value() is thread safe in this context,
it's still better to use it in the threads it belongs.
3v1n0 added 4 commits July 24, 2026 23:39
As pam_error() is just a definition for pam_prompt(), we can unify the
code to run them in the main action thread.

Add an helper to use conversations from the model in the main thread and
share the same code for all the conversations we trigger.
Ideally the last changes should make the conversation handling safer and
they seem to fix the issues when running in a local s390x container, but
we may still get failures.

So let's just skip the tests for the arch that seems to be problematic

Related to: canonical#966
@3v1n0
3v1n0 force-pushed the run-prompts-in-action-context branch from 28788b5 to 1ecdbdb Compare July 24, 2026 21:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

e2e-tests This issue is related to end-to-end tests / Run end-to-end tests on this pull request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants