[PR #706] [CLOSED] Fix application deadlock on keyevent in blank selectable Table. Fixes #705 #1023

Closed
opened 2026-03-04 01:09:04 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/rivo/tview/pull/706
Author: @darkhz
Created: 3/7/2022
Status: Closed

Base: masterHead: blank_table_app_deadlock


📝 Commits (1)

  • eb2c5c8 Fix application deadlock on keyevent in blank selectable Table. Fixes #705

📊 Changes

1 file changed (+7 additions, -0 deletions)

View changed files

📝 table.go (+7 -0)

📄 Description

Please see #705 for the initial details.

The issue occurs at this line:

lastColumn := t.content.GetColumnCount() - 1
rowCount := t.content.GetRowCount()

previous := func() {
		startRow := t.selectedRow
		startColumn := t.selectedColumn
		for {
			cell := t.content.GetCell(t.selectedRow, t.selectedColumn)
			if cell != nil && !cell.NotSelectable {
				return
			}
			t.selectedColumn--
			if t.selectedColumn < 0 {
				t.selectedColumn = lastColumn
				t.selectedRow--
				if t.selectedRow < 0 {
					t.selectedRow = rowCount - 1
				}
			}
			if t.selectedColumn == startColumn && t.selectedRow == startRow {
				t.selectedColumn = 0
				t.selectedRow = 0
				return
			}
		}
	}

As mentioned before, the Table is selectable, so the condition !cell.NotSelectable will return false, so the function does not return.

In a blank table with no rows and no columns, t.content.GetColumnCount() and t.content.GetRowCount() will return 0, and therefore lastColumn and rowCount will be evaluated to -1 and 0 respectively, which in turn will set selectedColumn and selectedRow to -1.

Consequently, t.selectedColumn and t.selectedRow will not match startColumn and startRow respectively, and therefore the function will not return. This in turn causes an infinite loop, with very high CPU usage.

A possible fix is to check whether lastColumn and rowCount-1 are negative values, before proceeding further.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/rivo/tview/pull/706 **Author:** [@darkhz](https://github.com/darkhz) **Created:** 3/7/2022 **Status:** ❌ Closed **Base:** `master` ← **Head:** `blank_table_app_deadlock` --- ### 📝 Commits (1) - [`eb2c5c8`](https://github.com/rivo/tview/commit/eb2c5c8d5f04b687eb0df45a11b430dc918a36b2) Fix application deadlock on keyevent in blank selectable Table. Fixes #705 ### 📊 Changes **1 file changed** (+7 additions, -0 deletions) <details> <summary>View changed files</summary> 📝 `table.go` (+7 -0) </details> ### 📄 Description Please see #705 for the initial details. The issue occurs at this [line](https://github.com/rivo/tview/blob/96063d6082f31f7f5b2d3a8fdc296251cc36514e/table.go#L1330): ```go lastColumn := t.content.GetColumnCount() - 1 rowCount := t.content.GetRowCount() previous := func() { startRow := t.selectedRow startColumn := t.selectedColumn for { cell := t.content.GetCell(t.selectedRow, t.selectedColumn) if cell != nil && !cell.NotSelectable { return } t.selectedColumn-- if t.selectedColumn < 0 { t.selectedColumn = lastColumn t.selectedRow-- if t.selectedRow < 0 { t.selectedRow = rowCount - 1 } } if t.selectedColumn == startColumn && t.selectedRow == startRow { t.selectedColumn = 0 t.selectedRow = 0 return } } } ``` As mentioned before, the Table is **selectable**, so the condition `!cell.NotSelectable` will return **false**, so the function does not return. In a blank table with no rows and no columns, `t.content.GetColumnCount()` and `t.content.GetRowCount()` will return 0, and therefore `lastColumn` and `rowCount` will be evaluated to -1 and 0 respectively, which in turn will set `selectedColumn` and `selectedRow` to -1. Consequently, `t.selectedColumn` and `t.selectedRow` will not match `startColumn` and `startRow` respectively, and therefore the function will not return. This in turn causes an infinite loop, with very high CPU usage. A possible fix is to check whether `lastColumn` and `rowCount-1` are negative values, before proceeding further. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-04 01:09:04 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/tview#1023
No description provided.