<p dir="auto">by <strong>pcrosby</strong>:</p>
<pre class="notranslate">In database/sql/sql.go, all the calls to db.putConn that use a defer will always pass
nil for the error.

For example, assuming the following exec function gets to the "defer db.putConn(ci,
err)" line, err will always be nil, no matter what happens to err after the
"defer..." line (since the arguments to the deferred function are evaluated
when the defer executes, not when the call executes).

I know putConn only cares if err is a driver.ErrBadConn, but it seems to me like that is
a possible error in many of the functions in sql.go that use this defer db.putConn(ci,
err) pattern.

func (db *DB) exec(query string, sargs []driver.Value) (res Result, err error) {
    ci, err := db.conn()
    if err != nil {
        return nil, err
    }
    defer db.putConn(ci, err)

    if execer, ok := ci.(driver.Execer); ok {
        resi, err := execer.Exec(query, sargs)
        if err != driver.ErrSkip {
            if err != nil {
                return nil, err
            }
            return result{resi}, nil
        }
    }

    sti, err := ci.Prepare(query)
    if err != nil {
        return nil, err
    }
    defer sti.Close()

    resi, err := sti.Exec(sargs)
    if err != nil {
        return nil, err
    }
    return result{resi}, nil
}</pre>
<div class="highlight highlight-source-go notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="d, _ := publicsuffix.EffectiveTLDPlusOne(&quot;foo.bar.golang.org&quot;)
fmt.Printf(&quot;%s\n&quot;, d)

d, _ = publicsuffix.EffectiveTLDPlusOne(&quot;foo.bar.golang.org.&quot;)
fmt.Printf(&quot;%s\n&quot;, d)"><pre class="notranslate"><span class="pl-s1">d</span>, <span class="pl-s1">_</span> <span class="pl-c1">:=</span> <span class="pl-s1">publicsuffix</span>.<span class="pl-en">EffectiveTLDPlusOne</span>(<span class="pl-s">"foo.bar.golang.org"</span>)
<span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"%s<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">d</span>)

<span class="pl-s1">d</span>, <span class="pl-s1">_</span> <span class="pl-c1">=</span> <span class="pl-s1">publicsuffix</span>.<span class="pl-en">EffectiveTLDPlusOne</span>(<span class="pl-s">"foo.bar.golang.org."</span>)
<span class="pl-s1">fmt</span>.<span class="pl-en">Printf</span>(<span class="pl-s">"%s<span class="pl-cce">\n</span>"</span>, <span class="pl-s1">d</span>)</pre></div>
<p dir="auto">prints</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="golang.org
org."><pre class="notranslate"><code class="notranslate">golang.org
org.
</code></pre></div>
<p dir="auto">In the 2nd example, the domain has a trailing dot. This is valid, as it indicates this is unambiguous FQDN. I was passing output from DNS records into EffectiveTLDPlusOne when I noticed this issue.</p>
<p dir="auto">I suggest the EffectiveTLDPlusOne ignores the trailing dot if one exists.</p>
<div class="highlight highlight-source-shell notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="$ go version
go version go1.4.2 darwin/amd64"><pre class="notranslate">$ go version
go version go1.4.2 darwin/amd64</pre></div>