Skip to content

Docker: Use tmux to control recording process #2796

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

Open
wants to merge 1 commit into
base: trunk
Choose a base branch
from
Open

Docker: Use tmux to control recording process #2796

wants to merge 1 commit into from

Conversation

VietND96
Copy link
Member

@VietND96 VietND96 commented Apr 20, 2025

User description

Thanks for contributing to the Docker-Selenium project!
A PR well described will help maintainers to quickly review and merge it

Before submitting your PR, please check our contributing guidelines, applied for this repository.
Avoid large PRs, help reviewers by making them as simple and short as possible.

Description

Motivation and Context

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • I have read the contributing document.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my changes.
  • All new and existing tests passed.

PR Type

Enhancement


Description

  • Refactored video recording process to use tmux for session control

  • Improved stopping and management of multiple recording sessions

  • Added tmux installation to Docker image dependencies

  • Enhanced process shutdown and session uniqueness logic


Changes walkthrough 📝

Relevant files
Enhancement
video.sh
Refactor recording control to use tmux sessions                   

Video/video.sh

  • Replaced direct ffmpeg process management with tmux-based session
    control
  • Added functions to stop, wait for, and check tmux recording sessions
  • Improved shutdown logic to handle all tmux sessions gracefully
  • Introduced unique tmux session naming for concurrent recordings
  • Updated recording start logic to launch ffmpeg in tmux sessions
  • +33/-22 
    Dependencies
    Dockerfile
    Add tmux to Docker image dependencies                                       

    Base/Dockerfile

    • Added tmux to the list of installed packages for the base image
    +1/-0     

    Need help?
  • Type /help how to ... in the comments thread for any questions about Qodo Merge usage.
  • Check out the documentation for more information.
  • Copy link

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling

    The stop_all_recording_and_wait function doesn't check if tmux is running before trying to list sessions, which could cause errors if called when no tmux sessions exist.

    function stop_all_recording_and_wait() {
      stop_all_recording
      for session in $(tmux list-sessions -F "#{session_name}"); do
        echo "Waiting for session '$session' to finish..."
        while tmux has-session -t "$session" 2>/dev/null; do
          sleep 1
        done
        echo "Session '$session' ended."
      done
    }
    Race Condition

    The tmux session naming logic might create race conditions if multiple recordings start simultaneously, as the index calculation isn't atomic.

    function get_tmux_session_unique_index() {
      tmux_index=$(tmux list-sessions 2>/dev/null | grep -o "${tmux_session_name}:[0-9]*" | cut -d: -f2)
      tmux_index=${tmux_index:-0}
      tmux_index=$((tmux_index + 1))
    }

    Copy link

    qodo-merge-pro bot commented Apr 20, 2025

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Impact
    Possible issue
    Filter tmux sessions properly

    The function should filter tmux sessions to only target video recorder sessions
    instead of sending quit signals to all tmux sessions. This could affect other
    tmux sessions that might be running on the system.

    Video/video.sh [144-151]

     function stop_all_recording() {
    -  current_record_sessions="$(tmux list-sessions -F "#{session_name}")"
    +  current_record_sessions="$(tmux list-sessions -F "#{session_name}" 2>/dev/null | grep "^${tmux_session_name}" || echo "")"
       echo "$(date -u +"${ts_format}") [${process_name}] - Current recording session(s): $current_record_sessions"
       for session in $current_record_sessions; do
         echo "Sending 'q' (quit signal) to session: $session"
         tmux send-keys -t "$session" 'q'
       done
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 9

    __

    Why: This is a critical fix that prevents the script from sending quit signals to unrelated tmux sessions, which could disrupt other processes running on the system. The improved code properly filters for only video recorder sessions.

    High
    Wait only for recorder sessions

    Similar to the previous function, this should only wait for video recorder
    sessions to finish, not all tmux sessions. Additionally, it should handle the
    case where tmux list-sessions returns an error if no sessions exist.

    Video/video.sh [153-162]

     function stop_all_recording_and_wait() {
       stop_all_recording
    -  for session in $(tmux list-sessions -F "#{session_name}"); do
    +  current_record_sessions="$(tmux list-sessions -F "#{session_name}" 2>/dev/null | grep "^${tmux_session_name}" || echo "")"
    +  for session in $current_record_sessions; do
         echo "Waiting for session '$session' to finish..."
         while tmux has-session -t "$session" 2>/dev/null; do
           sleep 1
         done
         echo "Session '$session' ended."
       done
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 8

    __

    Why: This suggestion fixes a significant issue where the script would wait for all tmux sessions to finish, not just video recording ones. It also properly handles the case where no sessions exist, preventing potential errors.

    Medium
    Return calculated session index

    The function doesn't actually return or export the calculated index value,
    making it ineffective. It calculates a value but doesn't make it available to
    the caller. Also, the pattern matching may not work correctly with the session
    naming convention used elsewhere.

    Video/video.sh [227-231]

     function get_tmux_session_unique_index() {
    -  tmux_index=$(tmux list-sessions 2>/dev/null | grep -o "${tmux_session_name}:[0-9]*" | cut -d: -f2)
    +  tmux_index=$(tmux list-sessions 2>/dev/null | grep -o "${tmux_session_name}[0-9]*" | sed "s/${tmux_session_name}//" | sort -n | tail -1)
       tmux_index=${tmux_index:-0}
       tmux_index=$((tmux_index + 1))
    +  echo $tmux_index
     }
    • Apply this suggestion
    Suggestion importance[1-10]: 7

    __

    Why: The function currently calculates a value but doesn't make it available to the caller. Adding the echo statement ensures the calculated index is returned, and the improved regex pattern better matches the session naming convention used elsewhere.

    Medium
    • Update

    Copy link

    qodo-merge-pro bot commented Apr 20, 2025

    CI Feedback 🧐

    (Feedback updated until commit 6f5f5de)

    A test triggered by this PR failed. Here is an AI-generated analysis of the failure:

    Action: Rerun workflow when failure

    Failed stage: Authenticate GitHub CLI for PR [❌]

    Failure summary:

    The action failed because the GitHub CLI authentication failed with the error: "missing required
    scope 'read:org'". The token provided in the GH_CLI_TOKEN_PR environment variable does not have the
    necessary permissions to perform the required operations. Specifically, it's missing the 'read:org'
    scope which is required for the GitHub CLI to authenticate properly.

    Relevant error logs:
    1:  ##[group]Operating System
    2:  Ubuntu
    ...
    
    22:  Issues: write
    23:  Metadata: read
    24:  Models: read
    25:  Packages: write
    26:  Pages: write
    27:  PullRequests: write
    28:  RepositoryProjects: write
    29:  SecurityEvents: write
    30:  Statuses: write
    31:  ##[endgroup]
    32:  Secret source: Actions
    33:  Prepare workflow directory
    34:  Prepare all required actions
    35:  Getting action download info
    36:  Download action repository 'actions/checkout@main' (SHA:85e6279cec87321a52edac9c87bce653a07cf6c2)
    37:  Complete job name: Rerun workflow when failure
    38:  ##[group]Run actions/checkout@main
    ...
    
    42:  ssh-strict: true
    43:  ssh-user: git
    44:  persist-credentials: true
    45:  clean: true
    46:  sparse-checkout-cone-mode: true
    47:  fetch-depth: 1
    48:  fetch-tags: false
    49:  show-progress: true
    50:  lfs: false
    51:  submodules: false
    52:  set-safe-directory: true
    53:  env:
    54:  GH_CLI_TOKEN: ***
    55:  GH_CLI_TOKEN_PR: ***
    56:  RUN_ID: 14603658636
    57:  RERUN_FAILED_ONLY: true
    58:  RUN_ATTEMPT: 1
    ...
    
    113:  Or undo this operation with:
    114:  git switch -
    115:  Turn off this advice by setting config variable advice.detachedHead to false
    116:  HEAD is now at 6cf04d0 Merge 6f5f5deafa8ad9cd267d4f191d1bcaa245e74b3b into be0c3462005ec6e57b451605b5fc92f8e57ac8af
    117:  ##[endgroup]
    118:  [command]/usr/bin/git log -1 --format=%H
    119:  6cf04d02d422c95052291e6fd8e7554eed680ce0
    120:  ##[group]Run sudo apt update
    121:  �[36;1msudo apt update�[0m
    122:  �[36;1msudo apt install gh�[0m
    123:  shell: /usr/bin/bash -e {0}
    124:  env:
    125:  GH_CLI_TOKEN: ***
    126:  GH_CLI_TOKEN_PR: ***
    127:  RUN_ID: 14603658636
    128:  RERUN_FAILED_ONLY: true
    129:  RUN_ATTEMPT: 1
    ...
    
    156:  Reading state information...
    157:  74 packages can be upgraded. Run 'apt list --upgradable' to see them.
    158:  WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
    159:  Reading package lists...
    160:  Building dependency tree...
    161:  Reading state information...
    162:  gh is already the newest version (2.69.0).
    163:  0 upgraded, 0 newly installed, 0 to remove and 74 not upgraded.
    164:  ##[group]Run echo "$GH_CLI_TOKEN_PR" | gh auth login --with-token
    165:  �[36;1mecho "$GH_CLI_TOKEN_PR" | gh auth login --with-token�[0m
    166:  shell: /usr/bin/bash -e {0}
    167:  env:
    168:  GH_CLI_TOKEN: ***
    169:  GH_CLI_TOKEN_PR: ***
    170:  RUN_ID: 14603658636
    171:  RERUN_FAILED_ONLY: true
    172:  RUN_ATTEMPT: 1
    173:  ##[endgroup]
    174:  error validating token: missing required scope 'read:org'
    175:  ##[error]Process completed with exit code 1.
    176:  Post job cleanup.
    

    Signed-off-by: Viet Nguyen Duc <nguyenducviet4496@gmail.com>
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    Successfully merging this pull request may close these issues.

    1 participant