-
Notifications
You must be signed in to change notification settings - Fork 1k
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
critical problem in revscriptsys globalevent think #3674
Conversation
When we create a `globalevent` of type `think` and we forget `globalevent:interval(milliseconds)` before `globalevent:register()`, the script is registered with the interval 0. As this is not checked before, no warning is given and the server runs the script non-stop causing 100% cpu. With this check, we guarantee that the script will not be registered if it does not have a set interval. The bug can be tested with this simple code: ``` local globalEvent = GlobalEvent('bugThink') function globalEvent.onTime() print('CPU says: "stop, it hurts!"') return true end -- globalEvent:interval(1000) globalEvent:register() ```
In my case only 7%~10% of the CPU, and also your code example is wrong ;), is onThink, not onTime, I do not know what others think, but if this does not block the server or make it slow, it should continue like this |
I have tested with a game dedicated server with some players online and I guarantee it's not a bad machine. If you need scripts to run at 0ms, you can set it to 1ms and good luck with your CPU percentage, but it has to be warned and not registered if the interval isn't changed in the script. edit: thanks for telling me about the code example, i replaced to onThink! |
I consider it critical because the script is registered with interval 0 without the programmer knowing, and depending on the scope of the function, the server will explode. I say this because you saw, with a simple print you got 10% cpu, now imagine more expensive scopes and with many players online. Bad situation because the programmer will not know whats happen. (I saw it happen in the pratictice) Setting a default value sounds good, but I still prefer that the script not register and display a warning. |
So in XML we can declare intervals of 0, but in Revscript not why is it forbidden. I think it is as simple as changing the type of the interval number to int64_t and that the default value is -1, then the events with intervals less than 0, cannot be registered, You could also add this warning in xml, and then everything would be consistent and familiar! If this is merged, this would happen: <globalevent name="example" interval="0" script="example.lua"/> -- work perfectly <3!
globalevent:interval(0)
globalevent:register() -- Error!!! can't register :D in my opinion it seems quite silly that something works differently if they are supposed to be the same I am not rejecting this PR, I just ask you to find some way to make it work the same for XML and Revscript, the warning seems good to me, since xml also has one. The truth is, you don't have to listen to me, you can expect the opinion of someone who agrees with you and can support the push of this PR. |
I would consider using XML deprecated at this point, everyone should start moving forward to Lua. |
Then don't use an interval, just use a while true loop |
This is good solution of course. Software should help prevent such unexpected misbehavior where possible, with informing the developer about the missing option. Any information is better, than no information. +1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Simple and elegant.
Very good.
When we create a `globalevent` of type `think` and we forget `globalevent:interval(milliseconds)` before `globalevent:register()`, the script is registered with the interval 0. As this is not checked before, no warning is given and the server runs the script non-stop causing 100% cpu. With this check, we guarantee that the script will not be registered if it does not have a set interval. The bug can be tested with this simple code: ``` local globalEvent = GlobalEvent('bugThink') function globalEvent.onTime() print('CPU says: "stop, it hurts!"') return true end -- globalEvent:interval(1000) globalEvent:register() ```
When we create a
globalevent
of typethink
and we forgetglobalevent:interval(milliseconds)
beforeglobalevent:register()
, the script is registered with the interval 0. As this is not checked before, no warning is given and the server runs the script non-stop causing 100% cpu. With this check, we guarantee that the script will not be registered if it does not have a set interval.The bug can be tested with this simple code: