Last active
December 29, 2015 03:09
-
-
Save aidanhs/7605681 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"database/sql" | |
"database/sql/driver" | |
"net/http" | |
"runtime" | |
"time" | |
) | |
type drv struct{} | |
type stmt struct{} | |
type conn struct{} | |
type rows struct{} | |
func init() { sql.Register("postgres", &drv{}) } | |
func (d *drv) Open(string) (driver.Conn, error) { return &conn{}, nil } | |
func (cn *conn) Prepare(string) (driver.Stmt, error) { return &stmt{}, nil } | |
func (st *stmt) Query([]driver.Value) (driver.Rows, error) { return &rows{}, nil } | |
func (st *stmt) NumInput() int { return 0 } | |
func (cn *conn) Close() error { return nil } | |
func (st *stmt) Close() error { return nil } | |
func (rs *rows) Close() error { return nil } | |
func (cn *conn) Begin() (driver.Tx, error) { panic("begin driver") } | |
func (st *stmt) Exec([]driver.Value) (driver.Result, error) { panic("Exec driver") } | |
func (cn *conn) Query(string, []driver.Value) (driver.Rows, error) { panic("Query string") } | |
func (cn *conn) Exec(string, []driver.Value) (driver.Result, error) { panic("Exec string") } | |
func (rs *rows) Next([]driver.Value) error { panic("Next row") } | |
func (rs *rows) Columns() []string { panic("columns rows") } | |
// ACTUAL LISTENER STARTS BELOW | |
var ( | |
mystmt *sql.Stmt | |
) | |
func main() { | |
runtime.GOMAXPROCS(1) | |
db, err := sql.Open("postgres", "") | |
if err != nil { | |
panic("open_err") | |
} | |
db.SetMaxIdleConns(1) | |
mystmt, err = db.Prepare("select 5 from pg_class limit 1") | |
if err != nil { | |
panic("prep_err") | |
} | |
println("starting") | |
for i := 0; i < 10; i++ { | |
go reqreq() | |
} | |
http.HandleFunc("/golang/abcdefg", abc) | |
if err := http.ListenAndServe(":9000", nil); err != nil { | |
panic("listen_err") | |
} | |
} | |
func reqreq() { | |
time.Sleep(1 * time.Second) | |
for { | |
resp, err := http.Get("http://localhost:9000/golang/abcdefg") | |
if err != nil { | |
panic("get_err") | |
} | |
resp.Body.Close() | |
} | |
} | |
func abc(http.ResponseWriter, *http.Request) { | |
_ = mystmt.QueryRow() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
go build -compiler=gccgo -o=go_malloc_panic -gccgoflags="-static-libgo -O3" conn.go | |
( | |
export GOTRACEBACK=2 | |
set -e | |
mkdir -p log | |
X=0 | |
while [ 1 ]; do | |
X=$(expr $X + 1) | |
killall go_malloc_panic 2>/dev/null || true | |
sleep 1 | |
./go_malloc_panic >./log/log_$X 2>&1 & | |
sleep 1 | |
done | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment