Ticket #43630

dai_auto_settler_run() gets stuck in recursion which somehow later leads to segfaults

Date d'ouverture: 2022-01-15 17:58 Dernière mise à jour: 2022-01-16 20:32

Rapporteur:
Propriétaire:
(Aucun)
Type:
État:
Ouvert
Composant:
(Aucun)
Jalon:
(Aucun)
Priorité:
5 - moyen
Sévérité:
5 - moyen
Résolution:
Aucun
Fichier:
Aucun

Détails

This is connected to several bits of info to know about it...

This line here:

/* Only known way to end in here is that hut turned in to a city
            • when settler entered tile. So this is not going to lead in any
            • serious recursion. */

This log here: : in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: Ramiro I: Failed to build city at (63, 31). Reason id: 34 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: Ramiro I: Failed to build city at (64, 31). Reason id: 34 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 2 times 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 2 times (total 4 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 4 times (total 8 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 8 times (total 16 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 16 times (total 32 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 32 times (total 64 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 64 times (total 128 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 128 times (total 256 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 256 times (total 512 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 512 times (total 1024 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 1024 times (total 2048 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 2048 times (total 4096 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 4096 times (total 8192 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 8192 times (total 16384 repeats) 1: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: last message repeated 16384 times (total 32768 repeats)

This stack trace here: Core was generated by /home/freeciv/freeciv/bin/freeciv-web --debug 1 --port 60 83 --Announce none --e'. Program terminated with signal SIGSEGV, Segmentation fault. #0 0x000056436a5ce510 in can_player_see_unit () #0 0x000056436a5ce510 in can_player_see_unit () #1 0x000056436a3d4f70 in send_unit_info () #2 0x000056436a49bdbf in illegal_action () #3 0x000056436a49da9e in unit_perform_action () #4 0x000056436a4a264b in unit_do_action () ---Type <return> to continue, or q <return> to quit--- #5 0x000056436a4f9a57 in dai_auto_settler_run () #6 0x000056436a4f997a in dai_auto_settler_run () #7 0x000056436a4f997a in dai_auto_settler_run () #8 0x000056436a4f997a in dai_auto_settler_run () #9 0x000056436a4f997a in dai_auto_settler_run () #10 0x000056436a4f997a in dai_auto_settler_run () #11 0x000056436a4f997a in dai_auto_settler_run () #12 0x000056436a4f997a in dai_auto_settler_run () #13 0x000056436a4f997a in dai_auto_settler_run () #14 0x000056436a4f997a in dai_auto_settler_run () #15 0x000056436a4f997a in dai_auto_settler_run () #16 0x000056436a4f997a in dai_auto_settler_run () #17 0x000056436a4f997a in dai_auto_settler_run () ...etc... 32751 more times....

Ticket History (3/13 Histories)

2022-01-15 17:58 Updated by: lexxie9952
  • New Ticket "dai_auto_settler_run() gets stuck in recursion which somehow later leads to segfaults" created
2022-01-15 18:19 Updated by: cazfi
Commentaire

Which kind of action enablers for the city founding the ruleset has?

In general that ai settler code seems unprepared for action enablers controlled city founding, but I have not yet analyzed it in more detail.

2022-01-16 16:56 Updated by: lexxie9952
Commentaire

Reply To cazfi

Which kind of action enablers for the city founding the ruleset has? In general that ai settler code seems unprepared for action enablers controlled city founding, but I have not yet analyzed it in more detail.

I do not know the ruleset that was used, but 80% of our singleplayer games choose classic rules. Still, that leaves a chance that it's another ruleset. Our mp2 actionenablers for those are 3, and look as follows:

actionenabler_build_city_pioneer action = "Found City" actor_reqs =

{ "type", "name", "range"
"UnitFlag", "Cities", "Local" "UnitState", "OnLivableTile", "Local" "MinMoveFrags", "1", "Local"
}

target_reqs =

{ "type", "name", "range", "present"
"CityTile", "Claimed", "Local", FALSE
}

actionenabler_build_city_domestic action = "Found City" actor_reqs =

{ "type", "name", "range", "present"
"UnitFlag", "Cities", "Local", TRUE "UnitState", "OnLivableTile", "Local", TRUE "MinMoveFrags", "1", "Local", TRUE "DiplRel", "Foreign", "Local", FALSE
}

actionenabler_build_city_fort action = "Found City" actor_reqs =

{ "type", "name", "range", "present"
"UnitFlag", "Cities", "Local", TRUE "UnitState", "OnLivableTile", "Local", TRUE "MinMoveFrags", "1", "Local", TRUE "Extra", "Fort", "Local", TRUE
}

In addition, Andreas seems to have added more debug info into stack trace and here's another one (getting several of these every day from singleplayers, even though only 0.25% of total games get it.)

debugging using libthread_db enabled Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1". Core was generated by /home/freeciv/freeciv/bin/freeciv-web --debug 1 --port 60 38 --Announce none --e'. Program terminated with signal SIGSEGV, Segmentation fault. #0 unit_transported (pcargo=pcargo@entry=0x556131b41a60)

at ../../freeciv/common/unit.c:2450

2450 || (!is_server() && pcargo->client.transported_by != -1)) { thread is 1 (Thread 0x7f2f0fb19800 (LWP 6367)) #0 unit_transported (pcargo=pcargo@entry=0x556131b41a60)

at ../../freeciv/common/unit.c:2450

---Type <return> to continue, or q <return> to quit--- #1 0x000055612afead4d in package_unit (packet=0x7ffe989df070,

punit=0x556131b41a60) at ../../freeciv/server/unittools.c:3135

#2 send_unit_info (dest=0x55612d291510, dest@entry=0x0,

punit=punit@entry=0x556131b41a60) at ../../freeciv/server/unittools.c:3245

#3 0x000055612b0b1d2f in illegal_action (pplayer=0x55612e5105a0,

actor=0x556131b41a60, stopped_action=27, tgt_player=0x55612d971800, target_tile=0x5561316b8df0, target_city=0x0, target_unit=0x0, disturb_player=true, requester=ACT_REQ_PLAYER) at ../../freeciv/server/unithand.c:2524

#4 0x000055612b0b3a0e in unit_perform_action (pplayer=0x55612e5105a0,

actor_id=1991, target_id=6960, sub_tgt_id=0, name=0x5561321e0990 "Derbent", action_type=27, requester=ACT_REQ_PLAYER) at ../../freeciv/server/unithand.c:3145

#5 0x000055612b0b85bb in unit_do_action ()

at ../../freeciv/server/unithand.c:5247

#6 0x000055612b10f9c7 in dai_do_build_city (punit=0x556131b41a60,

pplayer=0x55612e5105a0, ait=0x55612b745220 <ai_types>) at ../../../freeciv/ai/default/aisettler.c:1256

#7 dai_auto_settler_run (ait=ait@entry=0x55612b745220 <ai_types>,

pplayer=pplayer@entry=0x55612e5105a0, punit=punit@entry=0x556131b41a60, state=state@entry=0x55612d90dff0) at ../../../freeciv/ai/default/aisettler.c:1051

#8 0x000055612b10f8ea in dai_auto_settler_run ( ...thousands more of these dai_auto_settler_run come after....

P.S. is there a trick to make these messages have more readable formatting? Sorry for not knowing it.

2022-01-16 16:58 Updated by: lexxie9952
Commentaire

Well there's a clue, in mp2 rules, we do not have any reqs caring about if the cargo is transported, so I'm guessing it's one of the bundled rulesets tripping over the actionenabler req for cargo can't be transported?

2022-01-16 17:07 Updated by: lexxie9952
Commentaire

Another clue, I have so far never seen this crash in a longturn game which uses our rules. So if it's actionenabler and it's tripping in the checking for unit transported, it's all adding up to cause suspicion for checking this actionenabler req of not being transported, probably.

2022-01-16 17:17 Updated by: cazfi
Commentaire

Yeah, basically almost any non-standard requirement for those action enablers could cause that crash. The code is not prepared for such additional restrictions.

While waiting for a proper fix, you may need to just stop the recursion (remove the recursive call). That probably leads some AI settlers to never to do anything, but it's better than crashing.

2022-01-16 17:20 Updated by: lexxie9952
Commentaire

Well maybe it's opposite, and the fact we allow settling while still transported. Can I get a clue what I should do next to find it?

2022-01-16 17:23 Updated by: cazfi
Commentaire

Reply To lexxie9952

one of the bundled rulesets tripping over the actionenabler req for cargo can't be transported?

Which ruleset is that? I don't see it in classic or civ2civ3.

2022-01-16 17:25 Updated by: cazfi
Commentaire

Reply To lexxie9952

Well maybe it's opposite, and the fact we allow settling while still transported.

No. The recursion happens when settling is *disallowed* when the code assumes it to be allowed.

2022-01-16 17:36 Updated by: lexxie9952
Commentaire

instead of stop recursion and do nothing, is there a little less ugly hack like make it decide to deboard somewhere or do something else?

2022-01-16 19:41 Updated by: cazfi
Commentaire

Reserving this ticket for the proper fix. Opened a new ticket about emergency fix that will allow us to release 3.0.0 -> #43638

Opened also somewhat related ticket about unloading units in the end of amphibious goto -> #43639. That might help somewhat with your specific use-case.

2022-01-16 19:46 Updated by: cazfi
Commentaire

Reply To lexxie9952

: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: Ramiro I: Failed to build city at (63, 31). Reason id: 34

What is that "reason 34" (which ANEK_... is the 34) in your sources?

2022-01-16 20:32 Updated by: lexxie9952
Commentaire

Reply To cazfi

Reply To lexxie9952

: in dai_do_build_city() [../../../freeciv/ai/default/aisettler.c::1273]: Ramiro I: Failed to build city at (63, 31). Reason id: 34

What is that "reason 34" (which ANEK_... is the 34) in your sources?

/* Explanation not detected. */ ANEK_UNKNOWN,

Attachment File List

No attachments

Modifier

You are not logged in. I you are not logged in, your comment will be treated as an anonymous post. » Connexion