Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[bug] SSH connection leaked when update_config() raises an exception

オープン
#1,306 コメント 2 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

@tomsebastian10 がすでに取り組んでいます。

2026年3月21日 から。

  • #1307 @mn-ram による — マージされずにクローズ
  • #1310 @AYUSH676-JARVIS による — マージされずにクローズ

評価

難易度
2/5
見積もり時間
1〜3時間
初心者へのやさしさ
55/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
停滞
技術スタック
python

調査の方向性

openwisp_controller/connection/base/models.py の365–373行付近から始め、DeviceConnection.update_config() のフローを確認します。設定のプッシュに失敗するケースを再現し、その後、正常終了時と例外終了時の両方で SSH 接続が切断され、ファイルディスクリプタが開いたまま残らないことを確認します。

索引モデルが issue の本文から書いたものです。

説明

bug

● Describe the bug

In DeviceConnection.update_config(), the SSH connection is only closed
in the else block, which means it is never disconnected when an
exception occurs during a config push. Over time this leaks SSH file
descriptors and can crash the controller process with:

OSError: [Errno 24] Too many open files

● Steps To Reproduce

  1. Set up a device with an SSH DeviceConnection
  2. Make the config push fail intentionally (e.g. wrong credentials, unreachable device, or network drop mid-transfer)
  3. Observe that no disconnect() is called — the SSH session stays open
  4. Repeat for multiple devices; file descriptor count keeps growing

● Root cause (file + line)

File: openwisp_controller/connection/base/models.py
Lines: 365–373

def update_config(self):
    self.connect()
    if self.is_working:
        try:
            self.connector_instance.update_config()
        except Exception as e:
            logger.exception(e)
        else:
            self.disconnect()  # ← only runs when NO exception is raised

The else block in a try/except/else only executes when the try
block completes without raising. Any exception causes disconnect()
to be skipped entirely.


● Expected behavior

The SSH connection should always be closed after update_config()
completes — whether it succeeded or failed — to prevent file descriptor
leaks on production controllers.


● Proposed fix

Change else to finally:

def update_config(self):
    self.connect()
    if self.is_working:
        try:
            self.connector_instance.update_config()
        except Exception as e:
            logger.exception(e)
        finally:
            self.disconnect()  # ← runs always, success OR failure

● Screenshots

Not applicable (code-level bug).


● System Information

  • OS: Ubuntu 24.04 LTS
  • Python Version: Python 3.10+
  • Django Version: Django 4.2+
  • Browser and Browser Version (if applicable): Not applicable
主要言語
Python
スター
779
フォーク
328
平均マージ
2日 19時間
マージ済み PR(30日)
7

環境構築

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openwisp/openwisp-controller のほかの issue

openwisp/openwisp-controller の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。