<p>I'm having this weird problem with the lock files on Windows. Keep in mind that this is happening <strong>only</strong> on windows. I have zero problems with non-clearing lockfiles when I deploy to my linux server and have to restart the program. </p>
<p>Specs:</p>
<ul>
<li>Windows 7 64 bit</li>
<li>go1.4.2 32bit</li>
<li>git bash</li>
</ul>
<p>What happens is that the lockfile doesn't get emptied after a transaction is commited nor after the parent function of db.QueryRow returns.</p>
<p>For example the route:</p>
<pre><code>func SubmitPost(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
var tmp string
title := "test"
url := "test"
err = db.QueryRow("select title from posts where url==$1", title).Scan(&tmp)
tx, _ := db.Begin()
// if the record is in the database, delete it
if err == nil {
_, err2 := tx.Exec("delete from posts where title==$1;", title)
if err2 != nil {
log.Println("delete: ", err2)
}
}
_, err = tx.Exec("insert into posts values ($1, $2, $3, $4);", url, title, []byte("z"), time.now())
if err != nil {
log.Println("query: ", err)
}
if err = tx.Commit(); err != nil {
log.Println("commit: ", err)
}
}
</code></pre>
<p>Even if I just do the db.QueryRow, I still have the lockfile after my server exits.
This is the initialization of my db</p>
<pre><code>package main
import (
"database/sql"
"encoding/json"
"github.com/julienschmidt/httprouter"
"io/ioutil"
"log"
"net/http"
"time"
)
type Post struct {
Url string
Title string
Content string
Date time.Time
}
type Config struct {
Git string
Port string
Reload string
Submit string
Deploy string
}
var db *sql.DB
var config Config
func main() {
var err error
db, err = sql.Open("ql", "ql.db")
defer db.Close()
if err != nil {
log.Fatal(err)
}
router := httprouter.New()
router.GET(config.Submit, SubmitPost)
router.NotFound = Error404
log.Fatal(http.ListenAndServe(":8080", router))
}
</code></pre>
<p>Originally I was getting the lockfile not clearing because I wasn't deferring the database close. Now I am having the problem anytime a transaction is created. Is this something I should create an issue for on the tracker or am I crazy and missing something?</p>
<hr/>**评论:**<br/><br/>cryp7ix: <pre><p>Can you please put together a minimal reproduction case and post it to the github issue page of cznic/ql?</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传