Mirror of the lttng-dev mailing list
 help / color / mirror / Atom feed
From: jeremie.galarneau@efficios.com (Jérémie Galarneau)
Subject: [lttng-dev] [PATCH lttng-ust] Fix: Unsynchronized access in LTTngTCPSessiondClient
Date: Sat, 22 Feb 2014 15:19:15 -0500	[thread overview]
Message-ID: <CA+jJMxukg5xB-DEVV3M23piN8sMB2uqvt+rLs375ocRk61ndAQ@mail.gmail.com> (raw)
In-Reply-To: <204474029.28925.1393099864388.JavaMail.zimbra@efficios.com>

On Sat, Feb 22, 2014 at 3:11 PM, Mathieu Desnoyers
<mathieu.desnoyers at efficios.com> wrote:
> Other comments,
>
> ----- Original Message -----
>> From: "J?r?mie Galarneau" <jeremie.galarneau@efficios.com>
>> To: lttng-dev at lists.lttng.org
>> Sent: Thursday, February 20, 2014 11:22:33 AM
>> Subject: [lttng-dev] [PATCH lttng-ust] Fix: Unsynchronized access in  LTTngTCPSessiondClient
>>
>> enabledEventList is shared between the LTTngThread and eventTimer
>> threads but is not synchronized.
>>
>> This patch changes enabledEventList's type from an ArrayList to a
>> synchronizedList which implements the same interface.
>>
>> Signed-off-by: J?r?mie Galarneau <jeremie.galarneau at efficios.com>
>> ---
>>  .../org/lttng/ust/jul/LTTngTCPSessiondClient.java         | 15
>>  +++++++++++----
>>  1 file changed, 11 insertions(+), 4 deletions(-)
>>
>> diff --git a/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java
>> b/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java
>> index 25d1cb2..0d9a485 100644
>> --- a/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java
>> +++ b/liblttng-ust-jul/org/lttng/ust/jul/LTTngTCPSessiondClient.java
>> @@ -34,6 +34,7 @@ import java.util.List;
>>  import java.util.Timer;
>>  import java.util.TimerTask;
>>  import java.util.logging.Logger;
>> +import java.util.Collections;
>>
>>  class USTRegisterMsg {
>>       public static int pid;
>> @@ -57,7 +58,8 @@ public class LTTngTCPSessiondClient {
>>       private Semaphore registerSem;
>>
>>       private Timer eventTimer;
>> -     private List<LTTngEvent> enabledEventList = new ArrayList<LTTngEvent>();
>> +     private List<LTTngEvent> enabledEventList = Collections.synchronizedList(
>> +             new ArrayList<LTTngEvent>());
>
> I'd prefer:
>
>   private List<LTTngEvent> enabledEventList =
>          Collections.synchronizedList(new ArrayList<LTTngEvent>());
>
> unless you tell me that your coding style is more "java-like".
>
>>       /*
>>        * Map of Logger objects that have been enabled. They are indexed by name.
>>        */
>> @@ -86,7 +88,10 @@ public class LTTngTCPSessiondClient {
>>                                * We have to make a copy here since it is possible that the
>>                                * enabled event list is changed during an iteration on it.
>>                                */
>> -                             List<LTTngEvent> tmpList = new ArrayList<LTTngEvent>(enabledEventList);
>> +                             List<LTTngEvent> tmpList;
>> +                             synchronized(enabledEventList) {
>
> inconsistent style, missing space after "synchronized".
>
>> +                                     tmpList = new ArrayList<LTTngEvent>(enabledEventList);
>> +                             }
>>
>>                               LTTngSessiondCmd2_4.sessiond_enable_handler enableCmd = new
>>                                       LTTngSessiondCmd2_4.sessiond_enable_handler();
>> @@ -277,8 +282,10 @@ public class LTTngTCPSessiondClient {
>>                                                * Add the event to the list so it can be enabled if
>>                                                * the logger appears at some point in time.
>>                                                */
>> -                                             if (enabledEventList.contains(event) == false) {
>> -                                                     enabledEventList.add(event);
>> +                                             synchronized (enabledEventList) {
>> +                                                     if (enabledEventList.contains(event) == false) {
>> +                                                             enabledEventList.add(event);
>> +                                                     }
>
> Hrm, so what we want here is probably more a set than a list ? We want a data structure
> that does not have duplicates. If we can confirm that the order of the elements does not
> matter, a hash map might be a much more suited data structure than a list. We could
> then remove the explicit synchronize around "add".

Makes sense, I guess David (original author) will probably have an
opinion on that. My immediate concern was addressing the code's thread
safety.

Regards,
J?r?mie

>
> Thanks,
>
> Mathieu
>
>>                                               }
>>                                       }
>>                                       data = enableCmd.getBytes();
>> --
>> 1.9.0
>>
>>
>> _______________________________________________
>> lttng-dev mailing list
>> lttng-dev at lists.lttng.org
>> http://lists.lttng.org/cgi-bin/mailman/listinfo/lttng-dev
>>
>
> --
> Mathieu Desnoyers
> EfficiOS Inc.
> http://www.efficios.com



-- 
J?r?mie Galarneau
EfficiOS Inc.
http://www.efficios.com



  reply	other threads:[~2014-02-22 20:19 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-20 16:22 Jérémie Galarneau
2014-02-22 16:12 ` Mathieu Desnoyers
2014-02-22 19:15   ` Jérémie Galarneau
2014-02-22 20:08     ` Mathieu Desnoyers
2014-02-22 20:11 ` Mathieu Desnoyers
2014-02-22 20:19   ` Jérémie Galarneau [this message]
2014-02-25 21:32   ` [lttng-dev] [PATCH lttng-ust v2] " Jérémie Galarneau
2014-02-25 23:01     ` Mathieu Desnoyers

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CA+jJMxukg5xB-DEVV3M23piN8sMB2uqvt+rLs375ocRk61ndAQ@mail.gmail.com \
    --to=jeremie.galarneau@efficios.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox