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

add guard in lua against nil group from dead unit #232

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

uriba107
Copy link

@uriba107 uriba107 commented Jul 11, 2023

In 2.8.2 ED has changed the behaviour of :getGroup() for units. and it will return nil for dead units.
https://wiki.hoggit.us/view/DCS_func_getGroup

in current version, you would get an empty group and feed it to the exporter class which throws errors in dcs.log

2023-06-27 12:52:53.246 ERROR   dcs_grpc: Error in event handler: [string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\exporters\object.lua"]:49: attempt to index local 'group' (a nil value)
stack traceback:
	[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\exporters\object.lua"]:49: in function 'group'
	[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\exporters\object.lua"]:27: in function <[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\exporters\object.lua"]:19>
	(tail call): ?
	[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\methods\mission.lua"]:43: in function 'typed_exporter'
	[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\methods\mission.lua"]:341: in function <[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\methods\mission.lua"]:63>
	(tail call): ?
	[C]: in function 'xpcall'
	[string "C:\Users\Carmen\Saved Games\DCS.openbeta_server\Scripts\DCS-gRPC\grpc.lua"]:233: in function 'onEvent'
	[string "Scripts/World/EventHandlers.lua"]:13: in function <[string "Scripts/World/EventHandlers.lua"]:11>

The proposed change tests if the incoming group object is indeed a group (based on lua metatable) and return an empty table if it fails

Copy link
Collaborator

@rkusa rkusa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for the PR, highly appreciated!

@@ -45,6 +45,7 @@ GRPC.exporters.rawTransform = function(object)
end

GRPC.exporters.group = function(group)
if type(group) ~= "table" and getmetatable(group) ~= Group then return {} end
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think returning {} might lead to effects harder to debug than the current error we get. I haven't tested it, but I'd guess this would simply set all fields of the group to their default / undefined value which is probably unexpected in most cases.

Without giving it too much thought (so please feel free to challenge my suggestion), I think the following might be a better solution:

Wdyt?

Copy link
Author

@uriba107 uriba107 Jul 12, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I initially set it with return nil, but then I suspected that someone might try and iterate over a table. but you are correct. it will force someone to put some guards on his end if.

I'm unfamiliar grpc, reading your response, it's obvious that returning nil and specifying optional in the proto file is the correct way to go.

I'll make the changes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like marking the group property as optional as we have now complicated the handling of every client (and will probably break existing clients who are expecting group to always be there) for a, frankly stupid and god-knows-if-ED-are-going-to-do-something-about-it edge-case..

I haven't heard anyone complaining about missing events (that would have these nils and are currently not being published) so my question is.

What is the goal of this change?

  • Just stop the error messages appearing?
  • Publishing essential events that are currently not being published and being skipped due to the error?

If the former then this is an overkill solution and we could reduce the error verbosity for it. If the latter then I think I would like to explore others before we make a change that effects every event with a unit in it.

Options:

  • Create a DeadUnit / UnitWithoutGroup object instead and only use it for those events that need it.
  • ???

Copy link
Collaborator

@rkusa rkusa Jul 13, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fair point. I wouldn't mind reducing the DeadEvent down to just containing the unit's name instead of a whole unit object. At least in my use-cases, that is all I would need to cleanup state about the units I track in my clients. I'd probably even prefer it over a UnitWithoutGroup.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, I wouldn't be one complaining about missing Dead events, as I don't trust ED to fire that reliably anyway. So instead, I just consider a unit dead whenever I fetch information for it and receive a not found error 🤪

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ED is known to make a mess out for things.. for example, if a unit is dead and burning, it still exists as a staticObject until it's blows up. which is why I assume they disconnect it from the group as staticObjects cannot be assigned to groups.

It's super complicated to replicate but AFAIK you might see something like
TRUCK1(Unit in CONVOY) --> TRUCK1(burning staticObject) --> TRUCK1(dead Unit)

that's super tricky and follow the whole thing I'm afraid. which is sometimes the reason you feel the dead events are unreliable.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@uriba107 So this brings me back to my question: What is the goal of this PR for you? What is your priority?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My goal? Not seeing as many error messages in the log.
There is also a slight chance that once an error pops up dcs event handler will. Not continue processing more functions bound to that event but that might be just a feeling

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the most compatible (But not backwards compatible) solution here is the DeadUnit approach.

  1. It will get rid of error messages
  2. It will give people listening to events the ability to react on this event without needing to consult a local storage of units, which they would otherwise have to do if we just sent the unit ID. This may be important for simple stats trackers.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm currently trying to debug something on my end. I suspect it has something to do with the grpc throwing LUA errors on parse, but I'll need to be very targeted in my testing, so I'll build a simple test mission tonight and do some tests.

as to how it will be resolved eventually, I trust your judgment for choosing the correct path. but I want to first determine if it's a real issue, as I suspect, or purely cosmetic.

Copy link
Contributor

@rurounijones rurounijones left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment @ #232 (comment)

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

Successfully merging this pull request may close these issues.

None yet

3 participants