After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 583398 - SRV weight sorting is incorrect
SRV weight sorting is incorrect
Status: RESOLVED FIXED
Product: glib
Classification: Platform
Component: network
2.21.x
Other All
: Normal normal
: ---
Assigned To: gtkdev
gtkdev
Depends on:
Blocks:
 
 
Reported: 2009-05-21 02:41 UTC by Thadeu Lima de Souza Cascardo
Modified: 2009-06-01 18:32 UTC
See Also:
GNOME target: ---
GNOME version: 2.23/2.24


Attachments
git patch that fixes the bug based onto master (2.86 KB, patch)
2009-05-21 02:43 UTC, Thadeu Lima de Souza Cascardo
none Details | Review
a brief test case (658 bytes, text/plain)
2009-05-21 02:45 UTC, Thadeu Lima de Souza Cascardo
  Details
Fix multiple bugs in g_srv_target_list_sort() (11.49 KB, patch)
2009-05-28 19:44 UTC, Dan Winship
none Details | Review

Description Thadeu Lima de Souza Cascardo 2009-05-21 02:41:55 UTC
Please describe the problem:
    RFC 2782 says that targets with weight 0 should have a small chance of
    being selected. They should be put at the beginning of the list that
    will be used to run the selection algorithm, not so that they will be
    picked up first in the end of the process.

    Besides that, the random number should include the computed sum, and
    g_random_int_range has an open end. So we must add one to the range. And
    we must pick the target that has a greater OR EQUAL running sum.

Steps to reproduce:
  GList *list;
  list = g_list_append (NULL, g_srv_target_new ("a", 1, 1, 0));
  list = g_list_append (list, g_srv_target_new ("b", 1, 1, 0));
  list = g_list_append (list, g_srv_target_new ("c", 1, 1, 0));
  list = g_list_append (list, g_srv_target_new ("d", 1, 1, 10));
  list = g_list_append (list, g_srv_target_new ("e", 1, 0, 10));
  list = g_list_append (list, g_srv_target_new ("f", 1, 0, 20));
  list = g_srv_target_list_sort (list);
  while (list != NULL)
    {
      printf ("%s\n", g_srv_target_get_hostname (list->data));
      list = list->next;
    }

Actual results:
I see a b c before d all the time.

Expected results:
See d before a b c most of the time, but a before d some times.

Does this happen every time?


Other information:
Comment 1 Thadeu Lima de Souza Cascardo 2009-05-21 02:43:13 UTC
Created attachment 135062 [details] [review]
git patch that fixes the bug based onto master
Comment 2 Thadeu Lima de Souza Cascardo 2009-05-21 02:45:35 UTC
Created attachment 135063 [details]
a brief test case

I've built this including only gsrvtarget.[ch] stripped off the type/object system
Comment 3 Alexander Larsson 2009-05-25 10:43:29 UTC
danw: This is yours
Comment 4 Dan Winship 2009-05-28 19:44:19 UTC
Created attachment 135512 [details] [review]
Fix multiple bugs in g_srv_target_list_sort()

OK. In addition to the problems the reporter mentioned, there were
a few others, which meant that some allowable sortings couldn't actually
be generated.

I'm adding a test case too, however, the probabilities in the test case
come from just running the existing code and seeing how many copies of
each ordering were generated. It *looks* right though...
Comment 5 Dan Winship 2009-06-01 18:32:46 UTC
committed