How to fix: Chromedriver Page Immediately Closes - go

I run a program that tries to open a webpage using agouti/chromedriver in go, but as soon as it calls the new page, it closes the page. Subsequent attempts to access the page result in an "invalid session id" error. How can I get the page to stay open?
This is using Go (version 1.13.3 darwin/amd64) on Mac (version 10.14.5), with chromedriver (version 76.0.3809.68). I have the latest version of Google Chrome installed as well. I have tried updating chrome and agouti to no improved results. I have quit and restarted Chrome, uninstalled and reinstalled Chrome, and restarted my computer, none of which have worked. I have run with several chromedriver options (seen below), and run without them. I have tried with (seen below) and without time.Sleep() between functions. My regular chrome browser works fine.
package main
import (
"fmt"
"time"
"github.com/sclevine/agouti"
)
func main() {
driver := agouti.ChromeDriver(
agouti.ChromeOptions("args", []string{
"--headless",
"--no-sandbox",
"--disable-dev-shm-usage",
"--disable-gpu",
"--whitelisted-ips",
"--detach",
}),
agouti.Debug,
)
fmt.Println("start")
err := driver.Start()
if err != nil {
fmt.Println("Error starting driver: " + err.Error())
return
}
page, err := driver.NewPage(agouti.Browser("chrome"))
if err != nil {
fmt.Println("Error creating new page: " + err.Error())
return
}
time.Sleep(1 * time.Second)
err = page.Navigate("https://www.google.com")
if err != nil {
fmt.Println("Error navigating to job post link: " + err.Error())
return
}
time.Sleep(1 * time.Second)
fmt.Println("end")
}
When not using the --headless tag, I can see the browser window open and close in less than a second.
Expected output:
start
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809#{#864}) on port 53489
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
end
Actual Output:
start
Starting ChromeDriver 76.0.3809.68 (420c9498db8ce8fcd190a954d51297672c1515d5-refs/branch-heads/3809#{#864}) on port 53489
Only local connections are allowed.
Please protect ports used by ChromeDriver and related test frameworks to prevent access by malicious code.
Error navigating to job post link: failed to navigate: request unsuccessful: invalid session id

I found the solution; turns out I needed to reinstall chromedriver. Looking back through my logs, the issue occurred due to Chrome automatically updating overnight, and no longer working with my previous version of chromedriver.

Related

What causes urn:acme:error:unauthorized 403 error in golang's acme/autocert?

The full error message is:
403 urn:acme:error:unauthorized: Account creation on ACMEv1 is
disabled. Please upgrade your ACME client to a version that supports
ACMEv2 / RFC 8555. See
https://community.letsencrypt.org/t/end-of-life-plan-for-acmev1/88430
for details
And I've googled this and reviewed that link, but I'm just using:
golang.org/x/crypto/acme/autocert
package in a very normal way:
package main
import (
"crypto/tls"
"net/http"
"github.com/gin-gonic/gin"
"golang.org/x/crypto/acme/autocert"
)
func main() {
router := gin.Default()
hosts := []string{"yourdomain.com"}
certManager := autocert.Manager{
Prompt: autocert.AcceptTOS,
HostPolicy: autocert.HostWhitelist(hosts...),
Cache: autocert.DirCache("/certs"),
}
server := &http.Server{
Addr: ":https",
Handler: router,
TLSConfig: &tls.Config{
GetCertificate: certManager.GetCertificate,
},
}
server.ListenAndServeTLS("", "")
}
In fact this code has been running and working fine for the last 6 months. But just today I switched the server it was on and now get the above message.
I tried getting the very latest version of golang, but still same problem.
I changed my DNS for my hosts to this new server's ip and the hostname of the server is correct.
Far as I can tell, it's 100% identical to the previous working server but with a new IP.
Is golang's acme/autocert really this out of date and not using ACMEv2?
This statement:
In fact this code has been running and working fine for the last 6 months. But just today I switched the server it was on and now get the above message.
Might indicate that you're building against an older version of golang.org/x/crypto - check your go.mod file and ensure you're using a fairly recent version. I completed a project recently that uses almost identical code. The require in my go.mod looks like this:
golang.org/x/crypto v0.0.0-20200602180216-279210d13fed

process interrupted: signal: killed

I installed a utility called watcher.
https://github.com/canthefason/go-watcher
It works as expected using VS code.
But when I tried to use it in Goland (from Jetbrains) I get the following:
watcher main.go --port 8080
2020/03/04 14:10:42 build started
Building ....
2020/03/04 14:10:43 build completed
Running ...
2020/03/04 14:10:43 process interrupted: signal: killed
Needless to say go run main.go --port 8080 works.
I use a MAC Catalina.
Any suggestions?
Looks like an error from cmd.Wait()
if err := cmd.Wait(); err != nil {
log.Printf("process interrupted: %s \n", err)
...
A similar report was the OS killing the process because it was out of memory (OOM), and dmesg might have logged the error.

Client timeout exceeded while awaiting headers

I got below error, I am using go v1.10.4 linux/amd64.
I am not behind any firewall or whatsoever. New Relic in java server (same network segment) that we have runs fine.
We have tried:
Increasing the timeout to 60 seconds
Use http2 in the server
Using Postman return 503 with response:
{"exception":{"message":"Server Error","error_type":"RuntimeError"}}
troubleshooting with ./nrdiag says “No Issues Found”
Below is our code:
config := newrelic.NewConfig(os.Getenv("NEW_RELIC_APP_NAME"), os.Getenv("NEW_RELIC_KEY"))
config.Logger = newrelic.NewDebugLogger(os.Stdout)
app, err := newrelic.NewApplication(config)
if err != nil {
fmt.Println("Failed to create newrelic application", err)
os.Exit(1)
}
.................
httpListener, err := net.Listen("tcp", *httpAddr)
if err != nil {
oldlog.Print("Error: ", err)
logger.Log("transport", "HTTP", "during", "Listen", "err", err)
os.Exit(1)
}
g.Add(func() error {
logger.Log("transport", "HTTP", "addr", *httpAddr)
return http.Serve(httpListener, nrgorilla.InstrumentRoutes(httpHandler, app))
}, func(error) {
httpListener.Close()
})
}
However this what we got,note some_key was removed:
(28422) 2019/07/29 18:08:50.058559 {"level":"warn","msg":"application connect failure","context":{"error":"Post https://collector-001.eu01.nr-data.net/agent_listener/invoke_raw_method?license_key=some_key\u0026marshal_format=json\u0026method=connect\u0026protocol_version=17: net/http: request canceled (Client.Timeout exceeded while awaiting headers)"}}
I think it is due to DNS network timeout.
You can easily test this out by using the following steps (in Ubuntu)
Select the IPv4 Settings tab.
Disable the “Automatic” toggle switch and enter the DNS resolvers' IP addresses, separated by a comma. We’ll use the Google DNS nameservers:
8.8.8.8,8.8.4.4
If it works, then you may be able to reset the DNS to "Automatic"
On Windows OS, Running Linux Containers with WSL2, i followed the following steps,
Ran the command docker logout
Ran the command, docker network prune, so as to remove all the preconfigured settings of the network.
From Docker Settings, Enabled the DNS server configuration with 8.8.8.8
Restarted the Docker
Now executed login command with registry to login, docker login {registry}

Unable to create online web-page

I am trying to create Golang web-pages...
Progress:
Ubuntu 18.04 installed both locally and on a Linode VPS.
Created and compiled a local Golang "Hello World" script that renders OK both locally and online.
Created a net/http Golang script that works OK when called locally http://localhost:8080/testing to see if it works
Uploaded the script to the Linode server and initial status messages appear but when calling http:123.456.789.32:8080/testing to see if it works the browser freezes.
//
// Golang - main.go
//
package main
import (
"net/http"
)
func sayHello(w http.ResponseWriter, r *http.Request) {
message := r.URL.Path
message = "Hello " + message
w.Write([]byte(message))
}
func main() {
http.HandleFunc("/", sayHello)
if err := http.ListenAndServe(":8080", nil); err != nil {
panic(err)
}
}
There are no errors or warnings rendered and unable to find any log references.
Can error and warnings similar to PHP error_reporting(-1), declare(strict_types=1) etc be logged or rendered?
A quick check with Nmap showed this result:
nmap -sV -p 8080 <yourIP>
Starting Nmap 7.70 ( https://nmap.org ) at 2019-07-04 07:45 CEST
Nmap scan report for <your-domain>.com (<yourIP>)
Host is up (0.032s latency).
PORT STATE SERVICE VERSION
8080/tcp filtered http-proxy
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 0.90 seconds
The state of "filtered" actually means that there was no response on that port as opposed to an outright rejection of the request.
Check the output of iptables -L -n. Presumably, you have a firewall running and blocking port 8080. Do not simply deactivate the firewall, but read up on how to open port 8080 in the firewall product you are using. Linode has guides for the commonly used/preinstalled firewalls of various Linux distributions.
If you plan to go into production, please have someone help you to ensure security and availability of your deployment.

Golang (gin) server is going down without any trace

I tried making an API with gin.
router := gin.Default()
router.GET("/search", controllers.Search)
router.POST("/handshake/", controllers.Handshake)
router.GET("/ping", func(c *gin.Context) {
c.JSON(200, gin.H{
"message": "pong",
})
})
router.Use(gin.Recovery())
router.Run(fmt.Sprintf(":%d", 8080))
I am creating the binary on my local machine running ubuntu 18.04 and distributing the binary to ubuntu 16.04 on AWS EC2. the service runs fine and stops suddenly without any trace of error or warning or panic on the log. very difficult to find out what's wrong?

Resources