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

Errors after closing cube server. #525

Closed
jwalton opened this issue Mar 20, 2020 · 3 comments
Closed

Errors after closing cube server. #525

jwalton opened this issue Mar 20, 2020 · 3 comments
Labels
backend:server Issues relating to Cube Core's Server bug Something isn't working

Comments

@jwalton
Copy link
Contributor

jwalton commented Mar 20, 2020

Describe the bug

Basically, I have this reporting engine I'm writing using cube.js, and I started writing some integration tests which:

  • Write some data to the database
  • Start a new cube.js instance
  • Run a query to make sure we get back sensible data
  • Close the cube.js server.

This works, but after the test runs, while other tests are running, I get a bunch of errors like:

Error: Cannot use a pool after calling end on the pool
    at QueryQueue.parseResult (node_modules/@cubejs-backend/query-orchestrator/orchestrator/QueryQueue.js:97:13)
    at QueryQueue.executeInQueue (node_modules/@cubejs-backend/query-orchestrator/orchestrator/QueryQueue.js:86:19)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at node_modules/@cubejs-backend/query-orchestrator/orchestrator/QueryCache.js:250:17

To Reproduce

I have a test case that does:

    const server = new CubejsServer();
    try {
        // Run a query against the server.
    } finally {
        server.close();
    }

I tried to reproduce this by running cubejs create hello-world -d postgres, and then editing index.js to look like:

const CubejsServer = require('@cubejs-backend/server');
const CubejsClient = require('@cubejs-client/core');

function cubeJsLogger(msg, params) {
    if (params.error) {
        console.log(`${msg}\n${params.error}`);
    }
}

const server = new CubejsServer({
    logger: cubeJsLogger,
});

Promise.resolve()
    .then(async () => {
        const { port } = await server.listen();
        console.log(`🚀 Cube.js server is listening on ${port}`);

        const cubeClient = new CubejsClient.default('faketoken', {
            apiUrl: `http://localhost:${port}/cubejs-api/v1`,
        });

        const resultSet = await cubeClient.load({
            measures: ['Orders.count'],
            timeDimensions: [],
            filters: [],
        });
        console.log('******** - Got results');

        console.log('******** - Shutting down the server');
        server.close().catch(err => {
            console.log(`Close error: ${err.stack}`);
        });

        console.log('******** - Wait for a bit...');
        await new Promise(resolve => {
            setTimeout(resolve, 10000);
        });
        console.log('******** - Done');
    })
    .catch(err => {
        console.error(err.stack);
        process.exit(1);
    });

and this doesn't reproduce it... although instead it reproduced another error. The call to close() fails with:

TypeError: this.externalDriverFactory is not a function
    at getExternalDriverFactory (/Users/jwalton/tt/hello-world/node_modules/@cubejs-backend/server-core/core/index.js:427:39)
    at OrchestratorApi.releaseDriver (/Users/jwalton/tt/hello-world/node_modules/@cubejs-backend/server-core/core/OrchestratorApi.js:98:28)
    at OrchestratorApi.release (/Users/jwalton/tt/hello-world/node_modules/@cubejs-backend/server-core/core/OrchestratorApi.js:92:12)
    at /Users/jwalton/tt/hello-world/node_modules/@cubejs-backend/server-core/core/index.js:504:37
    at Array.forEach (<anonymous>)
    at CubejsServerCore.releaseConnections (/Users/jwalton/tt/hello-world/node_modules/@cubejs-backend/server-core/core/index.js:502:53)
    at CubejsServer.close (/Users/jwalton/tt/hello-world/node_modules/@cubejs-backend/server/index.js:108:23)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

-_-

Expected behavior

Server should stop trying to make queries after shutting down. Shutting down server should not error.

Version:
0.18.12

@paveltiunov paveltiunov added the bug Something isn't working label Mar 21, 2020
@paveltiunov
Copy link
Member

@jwalton Hey Jason! Thanks for heads up! Later one issue should be fixed now. In terms of tests it means driver somehow is reused. Do you pass any options to CubejsServer at all?

@paveltiunov paveltiunov reopened this Mar 21, 2020
@jwalton
Copy link
Contributor Author

jwalton commented Mar 23, 2020

Nothing too exciting:

const isProduction = process.env.NODE_ENV !== 'development';

const SCHEMA_PATH =
    process.env.NODE_ENV === 'production' ? 'dist/cubejs-schema' : 'src/cubejs-schema';

export async function startReportingServer() {
    const server = new CubejsServer({
        devServer: !isProduction,
        schemaPath: SCHEMA_PATH,
        logger: cubeJsLogger,

        contextToAppId: ({ authInfo }: { authInfo: AuthInfo }) =>
            `CUBEJS_ACCOUNT_${authInfo.accountId}`,

        queryTransformer: (query: any, { authInfo }: { authInfo: AuthInfo }) => {
            return query;
        },
    });

    const { port } = await server.listen();
    log.info(`Startup done - listening on port ${port}`);

    return { server, port };
}

@hassankhan hassankhan added the backend:server Issues relating to Cube Core's Server label May 5, 2021
@ivan-vdovin
Copy link
Contributor

Closing as it doesn't seem to be relevant

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend:server Issues relating to Cube Core's Server bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants