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/pool-improperly-destroyed #584

Closed
wants to merge 1 commit into from

Conversation

jszuminski
Copy link
Contributor

Description of the problem

  1. Called killPool() - it should kill the pool
  2. Called initPool() - instead of initializing the pool, we got this:
if (pool) {
    return log(4, '[pool] Already initialized, please kill it before creating a new one.');
 }

That's because pool = true, it was not set to false after destruction :)

Reported by an ADV user on FreshDesk.

@PaulDalek
Copy link
Contributor

Already resolved by the: https://github.com/highcharts/node-export-server/pull/586/files#diff-17a31987f7995e11080c24188e0c50f5fbf8436863484273cdb723444da78e5dR271.

@PaulDalek PaulDalek closed this Oct 23, 2024
@PaulDalek PaulDalek deleted the fix/pool-improperly-destroyed branch October 23, 2024 18:36
@LMcNulty-MA
Copy link

Hi @PaulDalek @jszuminski

I am running the latest build 4.0.2, and am currently experiencing the same issue originally mentioned.

Do you happen to know when the next release that will include this bug fix will be?

Thanks,
Logan

@PaulDalek
Copy link
Contributor

PaulDalek commented Nov 15, 2024

Hi @LMcNulty-MA,

Thanks for letting us know. I'll look into it. Could you please provide some more info about when it happens in your case? Do you use export server as a node module and direct calls of mentioned function result in the problem?

@LMcNulty-MA
Copy link

LMcNulty-MA commented Nov 15, 2024

@PaulDalek Thanks for the reply, I will be brief and to the point with my replication of the issue

  • I am simply sending highcharts options from python to the export server, and having the server send a .png image back to python
  • The FIRST post request works perfectly, and i get the image back.
  • But the SECOND request causes the server to fail, due to pool not actually being killed from first run

The following two files are what I'm using to produce this, and the highcharts-export-server.log is attached

Server.js - NOTE: This is the exact setup from the github documentation

const express = require('express');
const exporter = require('highcharts-export-server');

const app = express();
const port = 3000; // You can choose any port that's available

app.use(express.json()); // Middleware to parse JSON bodies


app.post('/export', async (req, res) => {
    const options = {
        export: {
            type: 'png',
            options: req.body
        }
    };
    // Initialize export settings with your chart's config
    const exportSettings = exporter.setOptions(options);

    // Must initialize exporting before being able to export charts
    await exporter.initExport(exportSettings);

    // Perform an export
    await exporter.startExport(exportSettings, async (error, info) => {
        const {result} = info;

        if (error) {
            res.status(500).send('Error exporting chart');
        } else {
            const imgBuffer = Buffer.from(result, 'base64');
            res.writeHead(200, {
                'Content-Type': 'image/png',
                'Content-Length': imgBuffer.length
            });
            res.end(imgBuffer);
        }
        
        // Kill the pool when we are done with it
        await exporter.killPool();
    });
});

app.listen(port, () => {
    console.log(`Highcharts export server running at http://localhost:${port}`);
});

python request file

import requests
import json

# The URL where your Node.js backend is running
url = 'http://localhost:3000/export'

# Define a simple chart configuration
chart_config = {
    "title": {"text": "My Chart Title"},
    "xAxis": {
        "categories": ["Apples", "Bananas", "Oranges"]
    },
    "series": [{
        "type": "bar",
        "data": [1, 2, 3]
    }]
}

# Send a POST request to the backend with the chart configuration
response = requests.post(url, json=chart_config)

# Check if the request was successful
if response.status_code == 200:
    # Save the received image to a file named 'chart.png' in the current directory
    with open('chart.png', 'wb') as file:
        file.write(response.content)
    print("Chart downloaded and saved as chart.png successfully.")
else:
    print("Failed to download chart. Status code:", response.status_code)
    print("Response content:", response.text)

highcharts-export-server.log

@LMcNulty-MA
Copy link

Hi @PaulDalek I'm so sorry to bother you, just wondering if you've had a chance to see the comment above, and if a fix may be in the works.. can't thank you enough

@PaulDalek
Copy link
Contributor

Hi @LMcNulty-MA,

My apologies for the delayed response. The code you are using comes from the Node.js Module section, which demonstrates the simplest way to export a single chart. At the end of the process, the killPool function is triggered. As stated in the documentation, this function Kills all workers in the pool, destroys the pool, and closes the browser instance. Once this occurs, further exports are no longer possible. If you intend to use the export server as a persistent server, you can enable it with the highcharts-export-server --enableServer true command. Alternatively, for a lighter approach, you can modify your code by removing the await exporter.killPool(); statement, which will result in a basic server.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants