Skip to content
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

Fix shell crash #297

Merged
merged 5 commits into from
Apr 21, 2020
Merged

Fix shell crash #297

merged 5 commits into from
Apr 21, 2020

Conversation

FedorZaytsev
Copy link
Collaborator

I have found an interesting crash when use ShellScriptTouchBarItem. You may get the following exception:

2020-04-19 19:18:45.592073-0700 MTMR[13222:2522041] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '*** -[NSConcreteTask terminationStatus]: task still running'
*** First throw call stack:
(
	0   CoreFoundation                      0x00007fff33e35d07 __exceptionPreprocess + 250
	1   libobjc.A.dylib                     0x00007fff6cb5a5bf objc_exception_throw + 48
	2   Foundation                          0x00007fff364f2336 -[NSConcreteTask terminationStatus] + 175
	3   MTMR                                0x000000010008114f $s4MTMR23ShellScriptTouchBarItemC7executeyS2SF + 1535
	4   MTMR                                0x000000010007f4c1 $s4MTMR23ShellScriptTouchBarItemC18refreshAndScheduleyyF + 401

if you have a script which take a long time to execute and you close the notebook. Probably the reason is that OS X put file system into sleep mode which trigger pipe.fileHandleForReading.readDataToEndOfFile() call to return while application is still running.

In this commit I am probably fixed this bug by using waitUntilExit call and by setting timeout on the script execution (execution timeout is equal to update interval).

P.S. Can maintainer release a new version please? I have features that I heavily rely on, so every time I restart my notebook I need to close distributed MTMR, then open XCode and run MTMR from it.

Fedor Zaitsev and others added 5 commits February 28, 2020 02:10
Added explanation for missing parameters (background, title and image)
AppleScriptTouchBarItem now allow to specify any number of icons which can be changed from the script. You cannot change icon from touch event. To change icon, you need to return array from your script with 2 values - title and icn name. More info in readme
When you execute Process from swift you cannot relay solely on pipe.fileHandleForReading.readDataToEndOfFile()
Sometimes when I close notebook I get exception saying that you cannot access process.terminationStatus variable while process is running.
Apparently it seems that this call can be finished when OS X put disks into sleep mode(?)

What I did:
1. Added Process.waitUntilExit() call
2. Added timeout (equal to the update interval)
@Toxblh Toxblh merged commit 52758f9 into Toxblh:master Apr 21, 2020
@bobrosoft
Copy link
Contributor

Hi @FedorZaytsev ,
Seems as I have 2 issues after that change with next preset:

{
    "type": "shellScriptTitledButton",
    "width": 80,
    "refreshInterval": 2,
    "source": {
      "inline": "top -l 2 -n 0 -F | egrep -o ' \\d*\\.\\d+% idle' | tail -1 | awk -F% '{p = 100 - $1; if (p > 30) c = \"\\033[33m\"; if (p > 70) c = \"\\033[30;43m\"; printf \"%s%4.1f%%\\n\", c, p}'"
    },
    "action": "appleScript",
    "actionAppleScript": {
      "inline": "activate application \"Activity Monitor\"\rtell application \"System Events\"\r\ttell process \"Activity Monitor\"\r\t\ttell radio button \"CPU\" of radio group 1 of group 2 of toolbar 1 of window 1 to perform action \"AXPress\"\r\tend tell\rend tell"
    },
    "align": "right",
    "image": {
      "base64":
      "iVBORw0KGgoAAAANSUhEUgAAAEAAAABACAMAAACdt4HsAAAABGdBTUEAALGPC/xhBQAAACBjSFJNAAB6JgAAgIQAAPoAAACA6AAAdTAAAOpgAAA6mAAAF3CculE8AAAA/1BMVEUAAADaACbYACfYACfjABzXACjYACfXACjYACfYACfYACfYACfdACLYACfXACjYACfVACv/AADXACjYACfYACfXACjYACfXACjaACXYACfYACfVACvYACfYACfZACbZACbYACfYACfZACb/AADYACfYACfVACrXACjVACu/AEDYACfYACfYACfXACjXACjYACfXACjYACfYACfYACfXACjYACfXACjYACfYACfZACbYACfYACfMADPYACfYACfYACfYACfYACfZACbXACjYACfYACfRAC7XACjYACfZACbWACnXACjXACjYACfTACzZACb/AADYACfYACfYACcAAAA+zneGAAAAU3RSTlMAItK+CVPjh3xUxPwPiGDQGAMtSKmN3Vk+wPQG/e26oIJBnwJCdiuAHgTmw+6BX+IgfaqLUvKOW8VKnagK+vBwYrhlc/urCznvhSyUbOEXPAFjGh/ektAAAAABYktHRACIBR1IAAAACXBIWXMAAA3XAAAN1wFCKJt4AAAAB3RJTUUH4ggW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EVYdFNvZnR3YXJlAHd3dy5pbmtzY2FwZS5vcmeb7jwaAAAAAElFTkSuQmCC"
    },
    "bordered": false
  },

Issues are:

  1. Update takes more than 2 seconds now (looks as 4, because of https://github.com/Toxblh/MTMR/pull/297/files#diff-41994de6f4662cc2cec06819ff822c55R67 ?) and because of that it's two times slower to update the data. refreshInterval is 2.
  2. I started to see "error" there instead of result from time to time (not happened before). If it can't be fixed, maybe we can skip update of the title (to not show "error").

If crash is around readDataToEndOfFile then maybe we can check if that method can be executed beforehand?

tomeresk pushed a commit to tomeresk/MTMR that referenced this pull request Jul 16, 2021
* Updated README

Added explanation for missing parameters (background, title and image)

* Implemented changable icons for AppleScriptTouchBarItem

AppleScriptTouchBarItem now allow to specify any number of icons which can be changed from the script. You cannot change icon from touch event. To change icon, you need to return array from your script with 2 values - title and icn name. More info in readme

* Fixed error related to ShellButton

When you execute Process from swift you cannot relay solely on pipe.fileHandleForReading.readDataToEndOfFile()
Sometimes when I close notebook I get exception saying that you cannot access process.terminationStatus variable while process is running.
Apparently it seems that this call can be finished when OS X put disks into sleep mode(?)

What I did:
1. Added Process.waitUntilExit() call
2. Added timeout (equal to the update interval)

Co-authored-by: Fedor Zaitsev <lobster@Fedors-MacBook-Pro.local>
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