{"action":"created","issue":{"url":"https://api.github.com/repos/cronvel/terminal-kit/issues/65","repository_url":"https://api.github.com/repos/cronvel/terminal-kit","labels_url":"https://api.github.com/repos/cronvel/terminal-kit/issues/65/labels{/name}","comments_url":"https://api.github.com/repos/cronvel/terminal-kit/issues/65/comments","events_url":"https://api.github.com/repos/cronvel/terminal-kit/issues/65/events","html_url":"https://github.com/cronvel/terminal-kit/issues/65","id":320528357,"number":65,"title":"Assistance with handling and tracking down the cause of: Error: .getCursorLocation() timed out","user":{"login":"MichaelLeeHobbs","id":6986471,"avatar_url":"https://avatars2.githubusercontent.com/u/6986471?v=4","gravatar_id":"","url":"https://api.github.com/users/MichaelLeeHobbs","html_url":"https://github.com/MichaelLeeHobbs","followers_url":"https://api.github.com/users/MichaelLeeHobbs/followers","following_url":"https://api.github.com/users/MichaelLeeHobbs/following{/other_user}","gists_url":"https://api.github.com/users/MichaelLeeHobbs/gists{/gist_id}","starred_url":"https://api.github.com/users/MichaelLeeHobbs/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/MichaelLeeHobbs/subscriptions","organizations_url":"https://api.github.com/users/MichaelLeeHobbs/orgs","repos_url":"https://api.github.com/users/MichaelLeeHobbs/repos","events_url":"https://api.github.com/users/MichaelLeeHobbs/events{/privacy}","received_events_url":"https://api.github.com/users/MichaelLeeHobbs/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2018-05-05T17:49:09Z","updated_at":"2018-05-07T08:30:58Z","closed_at":null,"author_association":"NONE","body":"I've built an SSH server to wrap some unsecured connections. Using terminal-kit for the interactive auth and menus. During interactive auth I've been having an issue where sometimes on slow vpn connections term.inputField will return an error of \"Error: .getCursorLocation() timed out\". I'm managed to solve this with: term.timeout = 3000 but that is not a very robust solution unless I pick some arbitrarily large value. but that could have its own issues. \r\n\r\nTo give a little background client's connect via varied Linux/Windows ssh clients. I'm using SSH2 on the server side. Once a shell is ready I create a terminal using the shells stream. From there on out its term(prompt) and term.inputField(...) to perform interactive two-factor auth as well as menu display/selection. Mainly, during login term.inputField will sometimes return Error: .getCursorLocation() timed out. Once it has done this it seems to kill stdin half of the stream. Thus it does not seem like it will be easy to recover from this error without creating the term.\r\n\r\n    _handleConnection(client, info) {\r\n       ...\r\n        client\r\n            ...\r\n            .on('session', (accept, reject)=> {\r\n                let session = accept()\r\n                this.logger(connectionData.id, connectionData.username, \"session start\")\r\n\r\n                session\r\n                    .on('shell', (accept, reject)=> {\r\n                        this.logger(connectionData.id, connectionData.username, \"shell opened\")\r\n                        connectionData.stream = accept()\r\n                        connectionData.term = term.createTerminal({stdin: connectionData.stream, stdout: connectionData.stream})\r\n                        connectionData.term.timeout = 3000\r\n                        connectionData.state = (connectionData.authMethod === 'interactive') ? 'auth' : 'mainMenu'\r\n                        connectionData.interval = setInterval(()=>this._connectionLoop(connectionData), 100)\r\n                    })\r\n        ...........\r\n\r\n    // called repeatedly from the auth code to get username/password/2FA token\r\n    _getInput({term, prompt, minLength = 1, maxLength = 128, maxTries = 3, tries = 0, isPassword = false, resolve, reject, connectionData = {id: '-', username: '-'}}) {\r\n        let internalFunc = ({term, minLength = 0, maxLength = 128, maxTries, tries, isPassword, resolve, reject})=> {\r\n            this.logger(connectionData.id, connectionData.username, `_getInput.internalFunc: ${prompt}`)\r\n            term(prompt)\r\n            term.inputField({echo: !isPassword, maxLength, minLength}, (error, input) => {\r\n                this.logger(connectionData.id, connectionData.username, `_getInput.internalFunc.term.inputField received: input = ${input} error = ${error}`)\r\n                term('\\r\\n\\r\\n')\r\n                if (error || !input || input === '') {\r\n                    if (tries < maxTries) {\r\n                        tries++\r\n                        this._getInput({term, prompt, minLength, maxLength, maxTries, tries, isPassword, resolve, reject, connectionData})\r\n                    } else {\r\n                        reject(error)\r\n                    }\r\n                } else {\r\n                    resolve(input)\r\n                }\r\n            })\r\n        }\r\n\r\n        if (resolve === undefined || reject === undefined) {\r\n            this.logger(connectionData.id, connectionData.username, `_getInput: ${prompt}`)\r\n            return new Promise((resolve, reject)=> {\r\n                this._getInput({term, prompt, minLength, maxLength, maxTries, tries, isPassword, resolve, reject, connectionData})\r\n            })\r\n        } else {\r\n            internalFunc({term, prompt, minLength, maxLength, maxTries, tries, isPassword, resolve, reject})\r\n        }\r\n    }\r\n\r\nI'd be grateful for some feedback on how to better handle the \"Error: .getCursorLocation() timed out\""},"comment":{"url":"https://api.github.com/repos/cronvel/terminal-kit/issues/comments/386996592","html_url":"https://github.com/cronvel/terminal-kit/issues/65#issuecomment-386996592","issue_url":"https://api.github.com/repos/cronvel/terminal-kit/issues/65","id":386996592,"user":{"login":"cronvel","id":6891714,"avatar_url":"https://avatars2.githubusercontent.com/u/6891714?v=4","gravatar_id":"","url":"https://api.github.com/users/cronvel","html_url":"https://github.com/cronvel","followers_url":"https://api.github.com/users/cronvel/followers","following_url":"https://api.github.com/users/cronvel/following{/other_user}","gists_url":"https://api.github.com/users/cronvel/gists{/gist_id}","starred_url":"https://api.github.com/users/cronvel/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/cronvel/subscriptions","organizations_url":"https://api.github.com/users/cronvel/orgs","repos_url":"https://api.github.com/users/cronvel/repos","events_url":"https://api.github.com/users/cronvel/events{/privacy}","received_events_url":"https://api.github.com/users/cronvel/received_events","type":"User","site_admin":false},"created_at":"2018-05-07T08:30:58Z","updated_at":"2018-05-07T08:30:58Z","author_association":"OWNER","body":"Hi @MichaelLeeHobbs ,\r\nWhat you did is probably already the best solution.\r\n\r\nTo give you some insight, the terminal \"protocol\" is not really reliable, and in fact, a terminal that does not handle a cursor location request will just silently ignore it, thus the only way to guess if it does not support that feature is to set up a timeout.\r\n\r\nSo increasing that timeout value is what you need to do.\r\n\r\nHowever, it sounds weird that you need to set it to a value as big as 3000 ms.\r\n\r\nDo you try to use Terminal-kit before the end of the SSH negotiation phase? (in your sample code, it seems that the terminal is created once the SSH connection is fully functional, but I'm not sure how the underlying lib works).\r\nIf so, I would suggest you to simply wait for a fully functional connection before using Terminal-kit high-level features like `.inputField()`, and set the the timeout to something like 500 ms.\r\n\r\nAlso it's worth noting that there is almost no side-effect with a big timeout value, except that if something is not working, it would take more time to fail.\r\n\r\nAlso that error does nothing with to SDTIN, you should still be able to use Terminal-kit even after that error."}}
{"actor":{"display_login":"cronvel"}}