Fixed a missing Unlocked mutex

Random log updates
This commit is contained in:
Farhan Khan 2022-01-13 22:55:35 -05:00
parent 160d140cf6
commit 6eaba2a3d5
8 changed files with 31 additions and 26 deletions

View File

@ -57,15 +57,15 @@ func stringexists(needle string, haystack []string) bool {
func getSettings() { func getSettings() {
c, err := ioutil.ReadFile("config.jsonc") c, err := ioutil.ReadFile("config.jsonc")
if err != nil { if err != nil {
logFatal.Fatal("Unable to open config.jsonc, exiting: ", err) logFatal("Unable to open config.jsonc, exiting: ", err)
} }
jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON jsoncbin := jsonc.ToJSON(c) // Calling jsonc.ToJSON() to convert JSONC to JSON
if jsonc.Valid(jsoncbin) == false { if jsonc.Valid(jsoncbin) == false {
logFatal.Fatal("Invalid jsonc, exiting.") logFatal("Invalid jsonc, exiting.")
} }
err = json.Unmarshal(jsoncbin, &settings) err = json.Unmarshal(jsoncbin, &settings)
if err != nil { if err != nil {
logFatal.Fatal("Unable to parse config.jsonc, exiting: ", err) logFatal("Unable to parse config.jsonc, exiting: ", err)
} }
} }

View File

@ -1,8 +1,9 @@
package main package main
import ( import (
"os"
"context" "context"
"os"
"github.com/jackc/pgx/v4/pgxpool" "github.com/jackc/pgx/v4/pgxpool"
) )
@ -13,7 +14,7 @@ func getDbPool() *pgxpool.Pool {
dburl := os.Getenv("DATABASE_URL") dburl := os.Getenv("DATABASE_URL")
pool, err := pgxpool.Connect(context.Background(), dburl) pool, err := pgxpool.Connect(context.Background(), dburl)
if err != nil { if err != nil {
logFatal.Fatal("Unable to connect to database:", err) logFatal("Unable to connect to database:", err)
} }
return pool return pool
} }

View File

@ -19,7 +19,7 @@ var ri_mutex = &sync.Mutex{}
func startpprof() { func startpprof() {
logInfo("Starting http/pprof on :7777") logInfo("Starting http/pprof on :7777")
logFatal.Fatal(http.ListenAndServe("127.0.0.1:7777", nil)) logFatal(http.ListenAndServe("127.0.0.1:7777", nil))
} }
func statusReportHandler() { func statusReportHandler() {

View File

@ -54,7 +54,7 @@ func BuildClient(endpoint string) http.Client {
proxyuri := fmt.Sprintf("socks5://%s:%d", settings.Proxies[ridx].Host, settings.Proxies[ridx].Port) proxyuri := fmt.Sprintf("socks5://%s:%d", settings.Proxies[ridx].Host, settings.Proxies[ridx].Port)
proxy, err := url.Parse(proxyuri) proxy, err := url.Parse(proxyuri)
if err != nil { if err != nil {
logFatal.Fatal("Error: ", err) logFatal("Error: ", err)
} }
tr.Proxy = http.ProxyURL(proxy) tr.Proxy = http.ProxyURL(proxy)
} }
@ -175,7 +175,7 @@ func LogInstance(endpoint string, o shared.RunningInstance) bool {
_, err = pool.Exec(context.Background(), "INSERT INTO instances (endpoint, state, software) VALUES($1, $2, $3)", endpoint, "", o.Software) _, err = pool.Exec(context.Background(), "INSERT INTO instances (endpoint, state, software) VALUES($1, $2, $3)", endpoint, "", o.Software)
if err != nil { if err != nil {
logWarn("Error inserting %s into `instances`: "+endpoint, err) logWarn("Error inserting ", endpoint+" into `instances`: ", err)
return true return true
} }

View File

@ -6,49 +6,53 @@ import (
) )
var ( var (
_logInfo *log.Logger _logInfo *log.Logger
_logErr *log.Logger _logErr *log.Logger
_logWarn *log.Logger _logWarn *log.Logger
_logConn *log.Logger _logConn *log.Logger
_logDebug *log.Logger _logDebug *log.Logger
logFatal *log.Logger _logFatal *log.Logger
) )
func logInit() { func logInit() {
_logInfo = log.New(os.Stdout, "INFO: ", log.Lmsgprefix|log.Ldate|log.Ltime) _logInfo = log.New(os.Stdout, "INFO: ", log.Lmsgprefix|log.Ldate|log.Ltime)
_logErr = log.New(os.Stdout, "ERR: ", log.Lmsgprefix|log.Ldate|log.Ltime) _logErr = log.New(os.Stdout, "ERR: ", log.Lmsgprefix|log.Ldate|log.Ltime)
_logWarn = log.New(os.Stdout, "WARN: ", log.Lmsgprefix|log.Ldate|log.Ltime) _logWarn = log.New(os.Stdout, "WARN: ", log.Lmsgprefix|log.Ldate|log.Ltime)
_logConn = log.New(os.Stdout, "CONN: ", log.Lmsgprefix|log.Ldate|log.Ltime) _logConn = log.New(os.Stdout, "CONN: ", log.Lmsgprefix|log.Ldate|log.Ltime)
_logDebug = log.New(os.Stdout, "DEBUG: ", log.Lmsgprefix|log.Ldate|log.Ltime) _logDebug = log.New(os.Stdout, "DEBUG: ", log.Lmsgprefix|log.Ldate|log.Ltime)
logFatal = log.New(os.Stdout, "FATAL: ", log.Lmsgprefix|log.Ldate|log.Ltime) _logFatal = log.New(os.Stdout, "FATAL: ", log.Lmsgprefix|log.Ldate|log.Ltime)
} }
func logInfo(s ...interface{}) { func logInfo(s ...interface{}) {
if (settings.LogLevel >= 1) { if settings.LogLevel >= 1 {
_logInfo.Print(s...) _logInfo.Print(s...)
} }
} }
func logErr(s ...interface{}) { func logErr(s ...interface{}) {
if (settings.LogLevel >= 2) { if settings.LogLevel >= 2 {
_logErr.Print(s...) _logErr.Print(s...)
} }
} }
func logWarn(s ...interface{}) { func logWarn(s ...interface{}) {
if (settings.LogLevel >= 3) { if settings.LogLevel >= 3 {
_logWarn.Print(s...) _logWarn.Print(s...)
} }
} }
func logConn(s ...interface{}) { func logConn(s ...interface{}) {
if (settings.LogLevel >= 4) { if settings.LogLevel >= 4 {
_logConn.Print(s...) _logConn.Print(s...)
} }
} }
func logDebug(s ...interface{}) { func logDebug(s ...interface{}) {
if (settings.LogLevel >= 5) { if settings.LogLevel >= 5 {
_logConn.Print(s...) _logDebug.Print(s...)
} }
} }
func logFatal(s ...interface{}) {
_logFatal.Fatal(s...)
}

View File

@ -94,7 +94,7 @@ func PollMastodonPleroma(endpoint string, o *shared.RunningInstance) {
req, err := http.NewRequest("GET", api_timeline, nil) req, err := http.NewRequest("GET", api_timeline, nil)
req.Header.Set("User-Agent", "Tusky") req.Header.Set("User-Agent", "Tusky")
if err != nil { if err != nil {
logFatal.Fatal("Unable to create new request for "+endpoint+": ", err) logFatal("Unable to create new request for "+endpoint+": ", err)
return return
} }

View File

@ -162,7 +162,7 @@ func check_activity(uri string) {
} }
_, err = pool.Exec(context.Background(), "INSERT INTO activities (document, normalized, instance, hashtags, bot) VALUES($1, $2, $3, $4, $5)", jsondocument, activityjson.normalized, activityjson.instance, hashtags, activityjson.bot) _, err = pool.Exec(context.Background(), "INSERT INTO activities (document, normalized, instance, hashtags, bot) VALUES($1, $2, $3, $4, $5)", jsondocument, activityjson.normalized, activityjson.instance, hashtags, activityjson.bot)
if err != nil { if err != nil {
logWarn("Error inserting %s into `activities`: "+uri, err) logWarn("Error inserting ", uri, " into `activities`: ", err)
return return
} }
@ -200,6 +200,7 @@ func check_actor(uri string) *ActorJson {
o.Recentactors.Mu.Lock() o.Recentactors.Mu.Lock()
i, cachedactorjson := o.Recentactors.Contains(uri) i, cachedactorjson := o.Recentactors.Contains(uri)
if i != -1 { if i != -1 {
o.Recentactors.Mu.Unlock()
cachedactorjson := cachedactorjson.(*ActorJson) cachedactorjson := cachedactorjson.(*ActorJson)
return cachedactorjson return cachedactorjson
} }
@ -208,7 +209,6 @@ func check_actor(uri string) *ActorJson {
selectRet := pool.QueryRow(context.Background(), "SELECT document FROM actors WHERE document->>'id' = $1", uri) selectRet := pool.QueryRow(context.Background(), "SELECT document FROM actors WHERE document->>'id' = $1", uri)
err := selectRet.Scan(&actorjson) err := selectRet.Scan(&actorjson)
if err == nil { if err == nil {
logWarn(actorjson)
return actorjson // Actor already in database, good! return actorjson // Actor already in database, good!
} }
@ -255,7 +255,7 @@ func check_actor(uri string) *ActorJson {
_, err = pool.Exec(context.Background(), "INSERT INTO actors (document, instance, bot) VALUES($1, $2, $3)", jsondocument, actorjson.instance, bot) _, err = pool.Exec(context.Background(), "INSERT INTO actors (document, instance, bot) VALUES($1, $2, $3)", jsondocument, actorjson.instance, bot)
if err != nil { if err != nil {
logWarn("Error inserting %s into `actors`: "+uri, err) logWarn("Error inserting ", uri, " into `actors`: ", err)
return nil // Unable to insert actor return nil // Unable to insert actor
} }

View File

@ -22,7 +22,7 @@ func StreamMastodon(endpoint string, o *shared.RunningInstance) {
req, err := http.NewRequest("GET", api_timeline, nil) req, err := http.NewRequest("GET", api_timeline, nil)
req.Header.Set("User-Agent", "Tusky") req.Header.Set("User-Agent", "Tusky")
if err != nil { if err != nil {
logFatal.Fatal("Unable to create new request for " + endpoint + ", exiting.") logFatal("Unable to create new request for " + endpoint + ", exiting.")
return return
} }