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

xml2js causes Bun to hang after sequential executions. #17224

Open
cryptofyre opened this issue Feb 10, 2025 · 2 comments
Open

xml2js causes Bun to hang after sequential executions. #17224

cryptofyre opened this issue Feb 10, 2025 · 2 comments
Labels
bug Something isn't working needs triage

Comments

@cryptofyre
Copy link

cryptofyre commented Feb 10, 2025

What version of Bun is running?

1.2.2+c1708ea6a

What platform is your computer?

Linux 6.6.62+rpt-rpi-2712 aarch64 unknown

What steps can reproduce the bug?

There appears to be an issue with xml2js in Bun where execution hangs and does not proceed as expected. When running a simple Node.js application that processes a provided XML file using this library, Bun consistently locks up on the second execution.

Interestingly, this behavior does not occur on the first run after package installation but reliably manifests on subsequent executions. While the exact cause remains unclear, the issue seems to originate from this specific point in execution.

Code Snippet.

const fs = require('node:fs');
const xml2js = require('xml2js');
const Logger = require('./logger');
const config = require('../config.json');
const logger = new Logger(config.logging);

const talkgroups = new Map();

function loadTalkgroups(xmlPath) {
    const xmlData = fs.readFileSync(xmlPath, 'utf8');
    const parser = new xml2js.Parser();

    parser.parseString(xmlData, (err, result) => {
        if (err) {
            console.error('Error parsing XML:', err);
            return;
        }

        // Process each alias in the playlist
        for (const alias of result.playlist.alias) {
            const talkgroupId = alias.id.find(id => id.$.type === 'talkgroup')?.$?.value;
            if (talkgroupId) {
                talkgroups.set(talkgroupId, {
                    name: alias.$.name,
                    group: alias.$.group,
                    color: alias.$.color
                });
            }
        }

        logger.success('Talkgroups', `Loaded ${talkgroups.size} talkgroups from playlist`);
    });
}

function getTalkgroupInfo(talkgroupId) {
    // Convert talkgroupId to string since XML values are stored as strings
    const id = String(talkgroupId);
    return talkgroups.get(id) || {
        name: 'Unknown Talkgroup',
        group: 'Unknown Department',
        color: '0'
    };
}

function getAllTalkgroups() {
    return Array.from(talkgroups.entries()).map(([id, info]) => ({
        id,
        ...info
    }));
}

module.exports = {
    loadTalkgroups,
    getTalkgroupInfo,
    getAllTalkgroups
};

I couldn't upload the XML that it's used with through GitHub so I've uploaded it via catbox.moe.
https://files.catbox.moe/m5lzr2.xml

What is the expected behavior?

The XML should be processed successfully and return the talkgroups as specified in the XML file.

[2025-02-10T06:26:33.683Z] [INFO] [Database] Database initialized successfully
[2025-02-10T06:26:34.366Z] [INFO] [Discord] Logging into Discord...
[2025-02-10T06:26:34.438Z] [SUCCESS] [Discord] Swimtrunks is ready!
[2025-02-10T06:26:35.216Z] [SUCCESS] [Talkgroups] Loaded 113 talkgroups from playlist
[2025-02-10T06:26:35.217Z] [INFO] [Talkgroups] Loaded talkgroup configurations
[2025-02-10T06:26:35.219Z] [INFO] [Processor] Started call processing (5000ms interval)
[2025-02-10T06:26:35.429Z] [INFO] [Monitoring] Updated channel description with system stats
[2025-02-10T06:26:35.430Z] [INFO] [Monitoring] Started system monitoring (60000ms interval)

Should be returned in console.

What do you see instead?

Instead it hangs at this stage.

[2025-02-10T06:26:33.683Z] [INFO] [Database] Database initialized successfully
[2025-02-10T06:26:34.366Z] [INFO] [Discord] Logging into Discord...
[2025-02-10T06:26:34.438Z] [SUCCESS] [Discord] Swimtrunks is ready!

Additional information

This is part of my project Swimtrunks, which can be located over at https://github.com/cryptofyre/Swimtrunks

@cryptofyre cryptofyre added bug Something isn't working needs triage labels Feb 10, 2025
@Jarred-Sumner
Copy link
Collaborator

This sounds silly but can you try setInterval(() => {}, 16) at the top of the your script and see if it still happens?

@cryptofyre
Copy link
Author

This sounds silly but can you try setInterval(() => {}, 16) at the top of the your script and see if it still happens?

Sorry for the late reply, this didn't seem to do anything.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

2 participants