<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/incubator-dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/incubator-dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<h3 dir="auto">Environment</h3>
<ul dir="auto">
<li>Dubbo version: 2.7.0</li>
<li>Operating System version: Mac OS</li>
<li>Java version: 1.8</li>
</ul>
<h3 dir="auto">Steps to reproduce this issue</h3>
<p dir="auto"><a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="338420654" data-permission-text="Title is private" data-url="https://github.com/apache/dubbo/issues/2031" data-hovercard-type="issue" data-hovercard-url="/apache/dubbo/issues/2031/hovercard" href="https://github.com/apache/dubbo/issues/2031">#2031</a> have fixed the writePlace stackOverflow issue. The code have been merged into hessian-lite, but not in dubbo.<br>
Right now, the issue still there in dubbo 2.7.0. But we are not able to embed hessian-lite, as we are not able to remove hessian from dubbo(conflicts as below).</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Found in:
    org.apache.dubbo:dubbo:jar:2.7.0:compile
    com.alibaba:hessian-lite:jar:3.2.5:compile
Duplicate classes:
    com/alibaba/com/caucho/hessian/io/HessianDebugState$DateState.class
    com/alibaba/com/caucho/hessian/io/ThrowableSerializer.class"><pre class="notranslate"><code class="notranslate">Found in:
    org.apache.dubbo:dubbo:jar:2.7.0:compile
    com.alibaba:hessian-lite:jar:3.2.5:compile
Duplicate classes:
    com/alibaba/com/caucho/hessian/io/HessianDebugState$DateState.class
    com/alibaba/com/caucho/hessian/io/ThrowableSerializer.class
</code></pre></div>
<ol dir="auto">
<li>Define a class with a writeReplace method return this</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="public class WriteReplaceReturningItself implements Serializable {

  private static final long serialVersionUID = 1L;

  private String name;

  WriteReplaceReturningItself(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  /**
   * Some object may return itself for wrapReplace, e.g.
   * https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java#L173
   */
  Object writeReplace() {
    //do some extra things

    return this;
  }
}"><pre class="notranslate"><code class="notranslate">public class WriteReplaceReturningItself implements Serializable {

  private static final long serialVersionUID = 1L;

  private String name;

  WriteReplaceReturningItself(String name) {
    this.name = name;
  }

  public String getName() {
    return name;
  }

  /**
   * Some object may return itself for wrapReplace, e.g.
   * https://github.com/FasterXML/jackson-databind/blob/master/src/main/java/com/fasterxml/jackson/databind/JsonMappingException.java#L173
   */
  Object writeReplace() {
    //do some extra things

    return this;
  }
}
</code></pre></div>
<ol start="2" dir="auto">
<li>Use Hessian2Output to serialize it</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="ByteArrayOutputStream bout = new ByteArrayOutputStream();
Hessian2Output out = new Hessian2Output(bout);

out.writeObject(data);
out.flush();"><pre class="notranslate"><code class="notranslate">ByteArrayOutputStream bout = new ByteArrayOutputStream();
Hessian2Output out = new Hessian2Output(bout);

out.writeObject(data);
out.flush();
</code></pre></div>
<ol start="3" dir="auto">
<li>Error occurs</li>
</ol>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)"><pre class="notranslate"><code class="notranslate">java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
</code></pre></div>
<p dir="auto">Pls. provide [GitHub address] to reproduce this issue.</p>
<h3 dir="auto">Expected Result</h3>
<p dir="auto">The serialization process should complete with no exception or error.</p>
<h3 dir="auto">Actual Result</h3>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)"><pre class="notranslate"><code class="notranslate">java.lang.StackOverflowError
  at com.alibaba.com.caucho.hessian.io.SerializerFactory.getSerializer(SerializerFactory.java:302)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:381)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
  at com.alibaba.com.caucho.hessian.io.Hessian2Output.writeObject(Hessian2Output.java:383)
  at com.alibaba.com.caucho.hessian.io.JavaSerializer.writeObject(JavaSerializer.java:226)
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have searched the <a href="https://github.com/apache/incubator-dubbo/issues">issues</a> of this repository and believe that this is not a duplicate.</li>
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox" checked=""> I have checked the <a href="https://github.com/apache/incubator-dubbo/blob/master/FAQ.md">FAQ</a> of this repository and believe that this is not a duplicate.</li>
</ul>
<p dir="auto"><a href="https://github.com/apache/incubator-dubbo/blob/6e4ff91dfca4395a8d1b180f40f632e97acf779d/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MetricsFilter.java#L44-L47">https://github.com/apache/incubator-dubbo/blob/6e4ff91dfca4395a8d1b180f40f632e97acf779d/dubbo-monitor/dubbo-monitor-api/src/main/java/org/apache/dubbo/monitor/support/MetricsFilter.java#L44-L47</a></p>
<p dir="auto">The way to calculate the invocation time can be improved by using <code class="notranslate">java.lang.System#nanoTime</code></p>