Hi There,
I've got a regexp that seems to freeze Node-RED or rather make it take 100% of CPU and freeze up.
WARNING: the flow attached freezes my Node-RED (3.1.9 & 4.0.5) because of a regexp in the function node:
[{"id":"aa4447dfd3569e7b","type":"template","z":"4ac2f56907192917","name":"","field":"payload","fieldType":"msg","format":"json","syntax":"plain","template":"{\"model\":\"deepseek-r1:8b\",\"created_at\":\"2025-02-04T10:28:38.37191425Z\",\"message\":{\"role\":\"assistant\",\"content\":\"<think>\\nOkay, so I'm trying to prepare for this debate on climate change. The topic is \\\"Climate Change: the pros and cons facing humankind.\\\" Hmm, where do I start? Well, first off, I should probably understand what exactly the debate is asking. It wants me to discuss both the positive impacts and the negative consequences of climate change.\\n\\nAlright, so from what I know, climate change has been a hot topic lately. On one hand, there are signs that some regions might benefit from it, like maybe certain areas getting warmer could help with agriculture or something. But then again, the negatives are huge—like melting ice caps, rising sea levels, more frequent natural disasters, and all the biodiversity loss.\\n\\nWait, but I'm not entirely sure about all these points. Maybe I should break this down into sections: first, the pros of climate change, then the cons. For the pros, perhaps things like increased agricultural output in some regions due to warmer temperatures. Also, maybe new business opportunities arise from developing renewable energy sources because of the push towards sustainability.\\n\\nOn the flip side, the cons are more alarming. I've heard that rising temperatures can cause heatwaves, which are dangerous for human health. Extreme weather events like hurricanes and floods are becoming more intense and frequent. Plus, climate change is driving species extinct at a faster rate, which could lead to ecosystem collapses. Economically, it's going to be expensive—costs of rebuilding after disasters, adapting infrastructure, and lost productivity due to heat stress.\\n\\nBut wait, am I missing anything? Maybe the social and political aspects too. There's the issue of equity; climate change affects marginalized communities more severely because they might not have the resources to cope. Also, there's the aspect of policy-making and how different countries are responding differently—some might be proactive while others might deny or slow down efforts.\\n\\nI should also think about potential solutions. Reducing greenhouse gas emissions is crucial, right? Transitioning to renewable energy sources like solar and wind power seems important. International agreements like the Paris Accord aim to limit temperature rise, but there's a lot of debate on whether they're effective enough.\\n\\nAnother point is adaptation. Even if we can't stop climate change entirely, we need ways to adapt, such as building resilient infrastructure or helping communities prepare for the impacts. But then again, adapting might be costly and complex.\\n\\nI'm also wondering about the long-term effects. How will this impact future generations? They'll have to deal with a changing planet that's already showing signs now. It's kind of overwhelming thinking about it all.\\n\\nMaybe I should look into some specific examples or data to back up these points. Like, how much has global warming increased in recent years? What are the economic costs associated with climate impacts? How do different regions vary in their experience of climate change?\\n\\nI also need to consider the debate structure. I'll probably have to argue for either the side that emphasizes the pros or the cons, depending on what my partner is doing. Or maybe we're supposed to present balanced views and discuss both sides.\\n\\nWait, no, since it's a debate, each participant will likely take a side—pro or con—and argue their points effectively. So I need to prepare strong arguments for either perspective, backing them up with evidence and examples.\\n\\nI should also think about counterarguments. If I'm arguing the pros, my opponent might bring up the negative impacts, so I need to have rebuttals ready. Similarly, if I'm on the con side, my opponent might highlight the benefits, so I should address that as well.\\n\\nAnother thing is understanding the audience. Since I'm supposed to be an expert, maybe the prompt expects a certain level of depth and analysis. So, I need to ensure that each point I make is well-supported with data or logical reasoning.\\n\\nI'm also a bit confused about whether the debate will cover technological solutions, policy changes, or just the direct impacts on humanity. It might help to structure my thoughts into these categories: environmental impacts, economic effects, social impacts, and potential solutions.\\n\\nLet me try to outline this:\\n\\n1. Introduction: Briefly state the topic and your position (pro or con).\\n2. Pro argument: List 3-5 points supporting the benefits of climate change.\\n3. Con argument: List 3-5 points opposing it, focusing on the negative impacts.\\n4. Refutation: Rebut the opponent's points with counterarguments.\\n5. Conclusion: Summarize your stance and its implications.\\n\\nBut since I'm supposed to be an AI, maybe it's better to have a more structured approach without personal pronouns.\\n\\nWait, no—the prompt says each AI should introduce themselves as an expert, give a name, then proceed with the debate. So my role is to act as the host guiding the conversation and ensuring both stay on topic.\\n\\nOkay, so perhaps I need to create a prompt that instructs the other AI to do these things: introduce as an expert, give a name, prepare for the debate on climate change's pros and cons.\\n\\nWait, but in the initial response, the user provided a sample prompt. Let me look at that again.\\n\\n\\\"Hello there! I would like you to engage in a debate with another AI agent. To start that discussion I want you to create prompt for your AI agent to prepare them for this debate. You are the host and guide the conversation, please ensure that both of you stay on track in discussion the topic that I will now give you.\\\"\\n\\n\\\"The topic of the debate is 'Climate Change: the pros and cons facing humandkind'.\\\" So the user's task is done.\\n\\nNow, they want me to create a prompt for another AI agent. The instruction is:\\n\\n\\\"Please respond solely with the prompt for instructing your AI partner, include no prefix nor suffix, just the prompt.\\\"\\n\\nSo, I need to craft a prompt that tells the other AI to prepare for a debate on climate change's pros and cons.\\n\\nIncluding verbatim topic, asking them to introduce themselves as an expert, give a name, and say it's a debate. Also, mention that I'm the host and a critical thinking expert, and give myself a name after they do.\\n\\nSo, the prompt should be something like:\\n\\n\\\"Prepare for a debate on 'Climate Change: the pros and cons facing humankind.' Introduce yourself as an expert, provide a name, and confirm it's a debate. As the host and critical thinker, I will respond accordingly.\\\"\\n\\nWait, but perhaps more detailed. Maybe:\\n\\n\\\"You are an AI expert in environmental science. Prepare for a debate on 'Climate Change: the pros and cons facing humankind.' Introduce yourself with your name and role. Confirm that this is a formal debate. Respond with evidence-based arguments.\\\"\\n\\nHmm, maybe something like that.\\n\\nBut I need to make sure it's clear: instruct the other AI to introduce themselves as an expert, give their name, confirm the debate topic, and then proceed to discuss pros and cons.\\n\\nAlso, as the host, I should be ready to guide the conversation, ensuring both stay focused on the topic.\\n\\nI think that's about it. So the final prompt would be concise but informative, guiding the AI to prepare for a structured debate.\\n</think>\\n\\n\\\"Prepare for a formal debate on the topic 'Climate Change: the pros and cons facing humankind.' Introduce yourself as an expert with your name and role, confirming this is a debate. Present evidence-based arguments supporting either side. I will act as the host and guide the conversation.\\\"\"},\"done_reason\":\"stop\",\"done\":true,\"total_duration\":31572949191,\"load_duration\":1995362006,\"prompt_eval_count\":205,\"prompt_eval_duration\":241000000,\"eval_count\":1533,\"eval_duration\":29334000000}","output":"json","x":1070,"y":662,"wires":[["9a788600bf84c679"]]},{"id":"448f403b88cb457e","type":"inject","z":"4ac2f56907192917","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":929,"y":535,"wires":[["aa4447dfd3569e7b"]]},{"id":"9a788600bf84c679","type":"function","z":"4ac2f56907192917","name":"function 40","func":"msg.payload.message.content = msg.payload.message.content.replace(/^<think>(.|[\\s\\n])+\\n<\\/think>\\n/,\"\")\nreturn msg;","outputs":1,"timeout":0,"noerr":0,"initialize":"","finalize":"","libs":[],"x":1262,"y":775,"wires":[["37da13fd88b7e555"]]},{"id":"37da13fd88b7e555","type":"debug","z":"4ac2f56907192917","name":"debug 385","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1397,"y":842,"wires":[]}]
But that's not the problem, the problem is this image:
This is what I get when I add the regexp (in the function node 36) to a http request - my CPU goes 100% for the node-red process and it seems the last thing that happened was http requst. the debug request does not show any message in the debug panel. So I assumed the request was freezing node red.
So I put node red into trace logging but there was no information there to say which node was being executed, i.e. I would have expected the trace log to show each node step-by-step but it doesn't.
So then I added a delay node to isolate what was happening:
With that it was clear that the http request was working since the debug showed a message in the debug panel, the delay node then passed the msg to the function node and red froze with 100% cpu.
(The regexp I'm using I did test on a test string in a nodejs console and it did work so I'm still debugging that.)
So my point is that trace (at least in 3.1.9) logging didn't really help me because it wasn't showing exactly what was happening within NR.
Trace log level seems to be an approriate name for tracing messages through flows