1
0
mirror of https://github.com/ManyakRus/starter.git synced 2025-11-25 23:02:22 +02:00

сделал //ping делать нельзя т.к. data race

This commit is contained in:
Nikitin Aleksandr
2025-05-05 16:13:13 +03:00
parent b7a16179ef
commit 592e06aef3

View File

@@ -53,6 +53,9 @@ type SettingsINI struct {
// TextConnBusy - текст ошибки "conn busy"
const TextConnBusy = "conn busy"
// timeOutSeconds - время ожидания для Ping()
const timeOutSeconds = 60
// Connect_err - подключается к базе данных
func Connect() {
@@ -374,7 +377,8 @@ loop:
//ping в базе данных
mutexReconnect.RLock() //race
err = GetConnection().Ping(ctx)
//err = GetConnection().Ping(ctx) //ping делать нельзя т.к. data race
err = Ping_err(ctx)
mutexReconnect.RUnlock()
if err != nil {
switch err.Error() {
@@ -503,3 +507,14 @@ func RawMultipleSQL(tx pgx.Tx, TextSQL string) (pgx.Rows, error) {
return rows, err
}
// Ping_err - выполняет пустой запрос для теста соединения
func Ping_err(ctxMain context.Context) error {
var err error
ctx, cancelFunc := context.WithTimeout(ctxMain, timeOutSeconds*time.Second)
defer cancelFunc()
_, err = GetConnection().Exec(ctx, ";")
return err
}