This is a read-only snapshot of the ComputerCraft forums, taken in April 2020.
Shirkit's profile picture

[1.5][SMP/SSP]World hangs after too many turtles on talking over Rednet

Started by Shirkit, 24 February 2013 - 07:15 AM
Shirkit #1
Posted 24 February 2013 - 08:15 AM
As I cannot start a new Bug Topic (prolly cause I just joined the forums), I'm going to post it over here.

[1.5][SMP/SSP]World hangs after too many turtles on talking over Rednet

I'm designing a code to build a massive quarry turtle, but instead of using a single turtle, I'm using a bunch of them (32) to mine an area really fast. But what happens is, after too many turtles have been placed and they start talking to the central computer, the Minecraft hangs (just like this bug report http://www.computerc...g-inaccessible/).

I can place blocks, but cannot open chest or anything. And I've tried waiting for 3 minutes and it didn't recover. I send up to 33 messages per tick (one per turtle), but that's from a single computer to all turtles (when they need an update). Most of the time I don't spam the Rednet, but it crashes when I do this massive update.

ComputerCraft Version Information: 1.5 Client / 1.5 Server
direwolf20 ModPack

Steps to reproduce:

- Create 2 turtles
- put this in one

rednet.open("right"); while true do rednet.send(PUT_ID_HERE,"hi"); end

- And this on the other

rednet.open("right"); while true do local id, message, distance = rednet.receive(); print(message); end

Conclusions
Server hangs after less than 1 second. It was told that was fixed in 1.5, but it's not.
Note that also was said that was a temporary hang. I waited more than 10 minutes without any luck.

Final note
Ok,I now this is rednet spam in an infinite loop, but what I mean is on my script I don't do that, sometimes I send more than 32 packets in a tick, and that's when it hangs (to different computers, of course).

Fix
For a temporary fix, I have limited my code to send 5 packets per tick. On my case that was possible.

Update
Just a quick update, even trying to limit how many packets per tick are sent in the Rednet, my server still hangs. This is actually sad. Hours of coding effort being thrown away =\

Update 2
And working with only 6 turtles on my script and JUST CompterCraft (in Forge, with Not Enough Items only) the server still freezes, and I'm not overflooding the rednet
Edited on 24 February 2013 - 04:06 PM
Lyqyd #2
Posted 24 February 2013 - 05:50 PM
Split into new topic.

This bug report is highly similar to other bug reports involving overuse of rednet.
Shirkit #3
Posted 24 February 2013 - 10:27 PM
The thing is I'm not spamming the RedNet in my case. I only send messages in timed places, and my server freezes even when 1-3 turtles are using the Rednet.

IMO, the problem is when 2 turtles (or computers, or even Rednet users) sends a message for the same receiver, when he does the rednet.receive(), the server freezes. I'm almost sure, because my server is freezing with 2 and 32 turtles, in a non-sense or deterministic way (that I can see)
immibis #4
Posted 25 February 2013 - 12:21 AM
Your example code contains an infinite loop.
Shirkit #5
Posted 25 February 2013 - 06:05 AM
That was just a case test, my code is located over here:

http://pastebin.com/mNtjB1UL
http://pastebin.com/yUHiVHsd

And infinite loops just mean repetitions, if I put a for loop to run, based on OS clock, for 5 seconds, the server still hangs.
Shirkit #6
Posted 27 February 2013 - 04:46 AM
Tested as many different scenarios I could come up with, and as I said, the problem is not the spam, but it seems that when the same computer receives two different messages in the same tick. Maybe messages should be put in a buffer instead of being required to be read in the same frame would solve that. Then even TCP could be implemented!
Cloudy #7
Posted 27 February 2013 - 06:20 AM
Uh… there's no requirement that messages are read in the same tick.
Shirkit #8
Posted 27 February 2013 - 02:16 PM
Uh… there's no requirement that messages are read in the same tick.

So how does it works if two messages arrive at the same tick?
Lyqyd #9
Posted 27 February 2013 - 02:21 PM
They remain in the event queue until they are pulled.
Shirkit #10
Posted 27 February 2013 - 08:43 PM
But how can I pull those messages? Using rednet.receive? Or must be with os.pullEvent?

And also, for how long do they stay in queue?
immibis #11
Posted 27 February 2013 - 10:00 PM
But how can I pull those messages? Using rednet.receive? Or must be with os.pullEvent?
Both. rednet.receive only calls os.pullEvent and discards non-rednet messages. rednet.receive also supports a timeout.

And also, for how long do they stay in queue?
Until you pull them.
Shirkit #12
Posted 28 February 2013 - 06:21 AM
Are you sure of this behavior? Cause I had problems of messages not being received, maybe I need a total review on my code knowing that, huuuum. Maybe I can send even less messages than what I'm sending.

Also, how does the Parallel API works? I tried firing 2 functions, in theory each one would run in a thread separated from the other, but in the end they are running in parallel. I wanted to put 2 forever loops in each thread, is that possible with this API?
immibis #13
Posted 28 February 2013 - 08:22 AM
Are you sure of this behavior? Cause I had problems of messages not being received, maybe I need a total review on my code knowing that, huuuum. Maybe I can send even less messages than what I'm sending.

Also, how does the Parallel API works? I tried firing 2 functions, in theory each one would run in a thread separated from the other, but in the end they are running in parallel. I wanted to put 2 forever loops in each thread, is that possible with this API?

Events are delivered to both coroutines.
Lyqyd #14
Posted 01 March 2013 - 06:57 AM
You were probably losing rednet messages due to turtle movements, sleep calls, or other event-destroying functions. These functions pull and discard events until they receive the one they are looking for.

Parallel runs two coroutines and passes all events received to both in turn.
Cranium #15
Posted 01 March 2013 - 07:35 AM
Oh, that's why I had to put a sleep(0) after some of my event pulls. I was not aware sleep() destroys the events in the queue.
karlsen #16
Posted 03 March 2013 - 01:07 AM
I'm sorry if I seem stupid but I have expirienced this problem aswell in 1.5, is it because of bad coding on my part or does it happen due to an actual "bug" with the rednet?
Shirkit #17
Posted 03 March 2013 - 06:43 AM
Well, I don't think it's bad coding since the code I've wrote isn't that bad and it's freezing. It can be, I'll rewrite it and then post some feedback.
immibis #18
Posted 03 March 2013 - 02:40 PM
Since it freezes the game it's still a bug - it shouldn't be possible for players to freeze servers.
Shirkit #19
Posted 08 March 2013 - 07:41 PM
Found out the problem. I was sending a lot of messages to a single turtle due to how my script was designed, and as it wasn't reading it, so ended up I was overflowing the buffer and causing the server to freeze. Fixed the problem on my script, but I still think the server shouldn't freeze.
Shirkit #20
Posted 12 March 2013 - 04:47 AM
Found out the problem. I was sending a lot of messages to a single turtle due to how my script was designed, and as it wasn't reading it, so ended up I was overflowing the buffer and causing the server to freeze. Fixed the problem on my script, but I still think the server shouldn't freeze.

And the note: I think the world is freezing due to a exploding the stack.
Cloudy #21
Posted 12 March 2013 - 05:43 AM
No.