[ 
https://issues.apache.org/jira/browse/HTRACE-119?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14339634#comment-14339634
 ] 

Masatake Iwasaki commented on HTRACE-119:
-----------------------------------------

Thanks for the comment [~cmccabe].

Trace#startSpan returns NullScope.INSTANCE if {{(isTracing() || s.next(info))}} 
is false. Users can call TraceScope#close without checking returned tracescope 
is NullScope.INSTANCE or not.
{code}
  TraceScope ts = null;
  try {
    ...
    ts = Trace.startSpan("MySpan");
    ... // do something traced
  } finally {
    if (ts != null) ts.close();
  }
{code}
This is not true if {{close}} of NullScope.INSTANCE is not callable multiple 
times because NullScope.INSTANCE is used in many places.

Now {{detach}} of NullScope.INSTANCE is not callable multiple times because 
NullScope.INSTANCE.detached is set to true once it is called. Users must check 
the tracescope is NullScope.INSTANCE or not in ordert to call {{detach}}.

Attached patch does not meant to allow double detach generally but only for 
NullScope.


> detach of NullScope singleton should not fail
> ---------------------------------------------
>
>                 Key: HTRACE-119
>                 URL: https://issues.apache.org/jira/browse/HTRACE-119
>             Project: HTrace
>          Issue Type: Bug
>    Affects Versions: master
>            Reporter: Masatake Iwasaki
>            Assignee: Masatake Iwasaki
>         Attachments: HTRACE-119.001.patch
>
>
> The {{detach}} method of NullScope singleton is possible to be called 
> multiple times by users avoiding conditionals by the assumption that 
> NullScope#close and NullScope#detach results in no-op. Calling {{detach}} of 
> NullScope singleton multiple times throws RuntimeException by HTRACE-101 now.



--
This message was sent by Atlassian JIRA
(v6.3.4#6332)

Reply via email to