[SERVER-9238] Shell stops working after long autocomplete operation Created: 04/Apr/13  Updated: 11/Jul/16  Resolved: 20/Sep/13

Status: Closed
Project: Core Server
Component/s: JavaScript, Shell
Affects Version/s: 2.4.1
Fix Version/s: 2.4.9, 2.5.3

Type: Bug Priority: Minor - P4
Reporter: David Verdejo Assignee: Mathias Stearn
Resolution: Done Votes: 3
Labels: autocomplete
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File Mongo_error.PNG    
Issue Links:
Duplicate
is duplicated by SERVER-10785 Shell Javascript timeout can render s... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Participants:

 Description   

When I try to use autocomplete on the shell, I receive the following error:
"JavaScript execution terminated"



 Comments   
Comment by Githook User [ 20/Dec/13 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-9238 Don't set a timeout in shell autocomplete

In V8, timeouts are fatal so the shell would become unusable if the
timeout fired. Since the timeout didn't cause remote calls to return
early (which is the most common cause of slow autocomplete), this didn't
actually do anything useful anyway.
Branch: v2.4
https://github.com/mongodb/mongo/commit/9ceadd4ece53d98762967b27bb897d09d912c1c8

Comment by auto [ 20/Sep/13 ]

Author:

{u'username': u'RedBeard0531', u'name': u'Mathias Stearn', u'email': u'mathias@10gen.com'}

Message: SERVER-9238 Don't set a timeout in shell autocomplete

In V8, timeouts are fatal so the shell would become unusable if the
timeout fired. Since the timeout didn't cause remote calls to return
early (which is the most common cause of slow autocomplete), this didn't
actually do anything useful anyway.
Branch: master
https://github.com/mongodb/mongo/commit/b7d4551298e2f55a46d42a9fff993c1e7e354883

Comment by J Rassi [ 16/Aug/13 ]

I've reproduced this:

  1. Run mongo --eval 'db.eval("sleep(5000);")' & mongo
  2. Type the following into the shell (within 4 seconds): db.<TAB>

The issue is related to the way that V8Scope objects implement execution time limits. The shell requests that autocompletion be interrupted if it does not finish within 1 second (and e.g. an autocomplete on a collection name will block if another thread is in possession of the global lock). See the following excerpt from mongo::generateCompletions():

shellMainScope->invokeSafe( "function callShellAutocomplete(x) {shellAutocomplete(x)}", &args, 0, 1000 );

SMScope::invoke() leaves the underlying scope intact after interruption. On the other hand, V8Scope::invoke() invalidates the underlying isolate (via V8::TerminateExecution()) during interruption, leaving shellMainScope unable to execute further code. Thus, this affects all shell versions that use V8 (2.4+).

Comment by Rock Li [ 26/Jun/13 ]

Any updates for this ticket?

I met the same issue.

It's a bit annoying and frustrating.

Comment by Tatyana Knaifel [ 20/May/13 ]

happened for me several times on Debian 6 machines.
execution of every command is being followed with that message
also when trying to autocomplete commands.

some examples:

rs:SECONDARY> db.stats()
Mon May 20 03:26:07.386 JavaScript execution terminated
error2:JavaScript execution terminated
rs:SECONDARY> show dbs;
Mon May 20 03:26:12.150 JavaScript execution terminated
error2:JavaScript execution terminated
rs:SECONDARY> rs.slaveOk()
Mon May 20 03:26:22.234 JavaScript execution terminated
error2:JavaScript execution terminated

after some time was fixed by reopening a shell.
(at first i have closed the shell and reopened it, but the problem still happened)

This wasn't the first time I have encountered this problem, and it was resolved this way every time.

Comment by Daniel Pasette (Inactive) [ 09/Apr/13 ]

I was able to reproduce twice on a linux machine. While running a load test, I attempted auto-completing for serverStatus by typing "db.serverS<TAB>" and got the same error, afterwards the shell was unusable and had to be restarted. After restarting, I tried tab completing on the collection name in "db.number<tab>" and had the same result. Haven't been able to repro since. This is with v2.4.1.

Comment by Tad Marshall [ 09/Apr/13 ]

I saw something like this on another user's machine here (linux), so it's not just you and it's not just Windows.

We'll try to figure out what goes wrong, perhaps working backwards from the case that I can reproduce (when I stop the server and then try to autocomplete something based on the 'db' variable). The difference in your case is that the server is not stopped, but it happens anyway.

Comment by David Verdejo [ 05/Apr/13 ]

I made more test today but I couldn't reproduce the error.

Please, could you close the ticket? If I could reproduce the error and
take more info, I will open a new one.

Kind regards,

Comment by Tad Marshall [ 04/Apr/13 ]

Interestingly, I don't get the extra "JavaScript execution terminated" text when I try this in Ubuntu 12.04 (testing 2.4.1 Linux-64).

Comment by Tad Marshall [ 04/Apr/13 ]

I think that I've seen something similar to what you've described, but I'm unable to duplicate this error following your steps with a working connection to a mongod server.

I tried with an exiting test.test collection and without one. The first tab completes as far as "getInd", a second tab does nothing (it probably beeps, but I have no sound on this machine) and a third tab displays the possible completions:

C:\MongoDB\241>mongo
MongoDB shell version: 2.4.1
connecting to: test
> use test
switched to db test
> db.test.insert({v:1})
> db.test.getInd
db.test.getIndexKeys(   db.test.getIndexSpecs(  db.test.getIndexStats(  db.test.getIndexes(     db.test.getIndices(
> db.test.getInd

I was able to get something more similar if I terminate the mongod server after starting the mongo shell. In the following output, the mongod was running when I started the shell, then I stopped it with ctrl-C before typing "db.test.getIn<tab>". I hit tab a second time and got the "trying reconnect" message followed by the "JavaScript execution terminated" message. I then hit return and got a redraw of my text (without the prompt), followed by another "JavaScript execution terminated" and then the final "error2:JavaScript execution terminated".

C:\MongoDB\241>mongo
MongoDB shell version: 2.4.1
connecting to: test
> db.test.getInThu Apr 04 11:34:26.852 Socket say send() errno:10054 An existing connection was forcibly closed by the remote host. 127.0.0.1:27017
  db.test.getIndThu Apr 04 11:34:31.183 trying reconnect to 127.0.0.1:27017
Thu Apr 04 11:34:32.198 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
Thu Apr 04 11:34:32.198 JavaScript execution terminated
  db.test.getInd
Thu Apr 04 11:34:40.294 JavaScript execution terminated
error2:JavaScript execution terminated

Is it possible that the mongod server connection was down when you were doing this test? I can get output like yours if the server is already known by the shell to be down before I try typing the command:

> db.test.getInThu Apr 04 11:43:20.325 JavaScript execution terminated
  db.test.getIn
Thu Apr 04 11:43:23.781 JavaScript execution terminated
error2:JavaScript execution terminated

This seems somewhat related to SERVER-8926. Autocomplete runs JavaScript to generate the list of autocompletions and it needs to talk to the server to resolve the collection name, so the "bonus" error message from JavaScript seems to be part of the problem.

For comparison, this is the output from version 2.2.4 when I try the test there:

C:\MongoDB\224>mongo
MongoDB shell version: 2.2.4
connecting to: test
>
> db.test.getIThu Apr 04 11:51:06 Socket say send() errno:10054 An existing connection was forcibly closed by the remote host. 127.0.0.1:27017
  db.test.getIndThu Apr 04 11:51:19 trying reconnect to 127.0.0.1:27017
Thu Apr 04 11:51:20 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017
  db.test.getInd
db.test.getIndexKeys(   db.test.getIndexSpecs(  db.test.getIndexes(     db.test.getIndices(
> db.test.getInd
test.test.getInd
Thu Apr 04 11:51:27 trying reconnect to 127.0.0.1:27017
Thu Apr 04 11:51:28 reconnect 127.0.0.1:27017 failed couldn't connect to server 127.0.0.1:27017

We don't get the "JavaScript execution terminated" text and we do get the autocompletions displayed, but we still get error messages mixed with the input text.

Generated at Thu Feb 08 03:19:47 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.