question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

setMaximumWorkerIdleTime(-1) doesn't disable worker timeout

See original GitHub issue

monaco-editor version: 0.15.6 Browser: Chrome 72.0.3626.96, Firefox 65.0, Edge 44.17763.1.0 OS: Windows 10 Pro 1809 (17763.253)

Steps or JS usage snippet reproducing the issue:

Navigate to the following JSFiddle: https://jsfiddle.net/jcoutch/vb76yo38/

After the Monaco editor loads, wait a few minutes, then start making changes in the loaded model. The ‘test-class’ reference will no longer be found by Monaco, even though the model is still loaded in memory, and I’m setting the maximum worker idle time to -1 to prevent the worker from going idle.

Even though the code is only setting the worker idle time for TypeScript, I’ve also tried setting the idle time on monaco.languages.typescript.javascriptDefaults with the same result.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Reactions:2
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
BennyHinrichscommented, Sep 5, 2019

@raedle I tried your suggestion and it seems to work for me, though it is annoying. I have a varying amount of files so I did this

setInterval(() => {
  const range = new monaco.Range(1,1,1,1);
  const addEmptySpace = {forceMoveMarkers: true, range, text: ' '};
  for (const m of monaco.editor.getModels()) {
    const toInvert = m.applyEdits([addEmptySpace]);
    m.applyEdits(toInvert);
  }
}, 50*1000)

It would be nice if this was something we could set in the configuration.

0reactions
raedlecommented, Aug 17, 2019

I was running into the same issue and found a workaround that worked in my case. The workaround makes an edit to the secondary (imported) model every 50s to prevent the typescript worker from killing itself.

The did not change in my case. It might change for projects with multiple models. Happy to hear back from others (if it worked).

Here is an example for the Monaco editor playground:

monaco.languages.typescript.typescriptDefaults.addExtraLib(
    `/**
* A simple species interface.
*/
export interface ISpecies {
    /**
    * Name of the species.
    */
    name: string;

    /**
    * Prints the noise of the animal to the console.
    * 
    * @param type {NoiseType} The noise type.
    */
    makeNoise(type: NoiseType): void;
}

export enum NoiseType {
    HAPPY,
    ANGRY,
}

/**
* A function that let's two species wrestle and returns an array with the winner at index 1
* and the second winner at index 2.
* 
* @param species1 {ISpecies} The first species 
* @param species2 {ISpecies} The second species 
*/
export declare function wrestle(species1: ISpecies, species2: ISpecies): [ISpecies, ISpecies]`,
    'file:///node_modules/@types/species/index.d.ts'
);

let secondaryModel = monaco.editor.createModel([
    `import { ISpecies, NoiseType } from './species';

abstract class Animal implements ISpecies {
    name: string;

    constructor(name: string) {
        this.name = name;
    }

    makeNoise(type: NoiseType): void {
        throw new Error('implement noise');
    }
}

export class Dog extends Animal {
    constructor(name: string) {
        super(name);
    }

    makeNoise(type: NoiseType): void {
        switch (type) {
            case NoiseType.HAPPY:
                console.log('woof');
                break;
            case NoiseType.ANGRY:
                console.log('growl');
                break;
        }
    }
}

export class Horse extends Animal {
    constructor(name: string) {
        super(name);
    }

    makeNoise(type: NoiseType): void {
        switch (type) {
            case NoiseType.HAPPY:
                console.log('neigh');
                break;
            case NoiseType.ANGRY:
                console.log('$%@Y&%#');
                break;
        }
    }
}`
].join('\n'), "typescript", monaco.Uri.file("./animals.ts"));

let primaryModel = monaco.editor.createModel([
    `import { wrestle, NoiseType } from 'species';
import { Dog, Horse } from './animals';

const dog = new Dog('Rantanplan');
const horse = new Horse('Jolly Jumper');

const [victor, vanquished] = wrestle(dog, horse);

console.log(\`The winner is \${victor.name}\`);

victor.makeNoise(NoiseType.HAPPY);
vanquished.makeNoise(NoiseType.ANGRY);

`
].join('\n'), 'typescript', monaco.Uri.file('./main.ts'));

monaco.editor.create(document.getElementById("container"), {
    model: primaryModel,
    language: "javascript"
});

// The worker service will kill itself after 60-90s. To prevent this
// behavior, we'll make and revert an edit every 50s. This is a workaround
// but it seems to do the trick.
setInterval(() => {
    const range = new monaco.Range(1, 1, 1, 1);
    const addEmptySpace = {
        forceMoveMarkers: true,
        range,
        text: ' '
    };

    const invertedEdits = secondaryModel.applyEdits([addEmptySpace]);
    secondaryModel.applyEdits(invertedEdits);
}, 50 * 1000);
Read more comments on GitHub >

github_iconTop Results From Across the Web

gunicorn - Frequent worker timeout - Stack Overflow
It works like a clock.. So, Do: 1) open the gunicorn configuration file. 2) set the TIMEOUT to what ever you need -...
Read more >
How to resolve the gunicorn critical worker timeout error?
If above fix doesn't work, then increase Gunicorn timeout flag in Gunicorn configuration, default Gunicorn timeout is 30 seconds.
Read more >
Gunicorn increase timeout doesnt takes effect - DigitalOcean
I have a minimal flask api deployed on digital ocean wich trhows this error when i do a large request: [1] [CRITICAL] WORKER...
Read more >
monaco-editor | Yarn - Package Manager
Fast, reliable, and secure dependency management.
Read more >
CHANGELOG.md - code room
Thank you Contributions to `monaco-editor`: * [Sebastián Gurin (@cancerberoSgx)](https://github.com/cancerberoSgx): fix worker paths in parcel [PR ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found