Author Archives: Robins

Popen error: cannot allocate memory [How to Solve]

 

Foreword

This is a bug found in the actual project. After the device runs for a period of time, an error is reported: Poppen error: cannot allocate memory. Operating platform: Xintang nuc970, memory 64M, Linux kernel version: 3.10.108 +.


1. Popen introduction

The Popen function creates a child process to execute Shell, and shell A sub process is created to execute commands. From the practice process, it can be seen that after the process allocates memory and fills the process stack space, these functions fail to execute and return enomem error code cannot allocate memory. As long as the space is not released, the execution fails all the time

2. Cause analysis of Popen error

Here is a test program to reproduce the problem: the main thread malloc applies for heap space and fills the stack space of the process; Another thread performs the Popen operation. The result is that when the routine thread executes Popen, it always reports a Popen error: cannot allocate memory error until the main thread executes the free operation.

1. System memory of the device

2. Run the test program./test  , Max statck size is just 8m

3. Results: when the process is running, an error is reported when the heap space exceeds 8m, but in fact, the memory in the system is still sufficient, with more than 37m.

4. Once the space requested by malloc is released, it will return to normal immediately

5. Test program source code

#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include <stdlib.h>
#include <sys/sysinfo.h>

#define SIZE (1024*1024*1)
#define MEM_SIZE (45)

void *routine(void *arg)
{
	struct sysinfo info;
	
	while(1)
	{		
		sysinfo(&info);
		printf("freeram = %ld\n",info.freeram);
		
		FILE* fp = popen("cat /sys/class/net/eth0/carrier", "r");
		if(fp == NULL)
		{
			printf("popen error:%s\n", strerror(errno));
			sleep(1);
			continue;
		}
		
		char  buffer[1024];
		int   bytes_read = fread(buffer, 1, sizeof(buffer), fp);
		pclose(fp);

		printf("popen ok %2x\n",buffer[0]);			
		sleep(1);
		
	}
}

int main(int argc, char **argv)
{
		
	pthread_t tid;
	pthread_create(&tid, NULL, routine, NULL);
	

	unsigned int *p = (unsigned int *)malloc(1024 * 1024 * MEM_SIZE);
	printf("malloc buffer: %p\n", p);

	for (int i = 0; i < 1024 * 1024 * (MEM_SIZE/sizeof(int)); i++) 
	{
		p[i] = 123;
		if ((i & 0xFFFFF) == 0) 
		{
			printf("%dMB written\n", i >> 18);
			sleep(1);
			//usleep(100000);
		}

	}

	
	while(1)
	{
		sleep(20);
		if(p)
		{
			printf("free mem\n"); //The popen call is normal after the memory is released
			free(p);
			p = NULL;
		}
	}
	
	return 0;
}

Summary

The system overhead of functions such as Popen is very high. When the process memory is tight, it is easy to make mistakes. If the requested memory space is not released in time, the execution fails all the time.

[Solved] R Language Error: Error in RStudioGD() : Shadow graphics device error: r error 4 (R code execution error)

R Language Error: Error in RStudioGD() : Shadow graphics device error: r error 4 (R code execution error)

 

Solution:

Solution 1: Ctrl + Shift + F10 to restart your session
solution 2: run the following code directly to regenerate the temporary file without restarting (recommended)

dir.create(tempdir())

You have 77 PMD violations maven error [How to Solve]

Maven compilation exception

Failed to execute goal org.apache.maven.plugins:
maven-pmd-plugin:3.8:check (default) 
on project xxx: You have 133 PMD violations. 

Reason: PMD verification is added to Maven to judge whether your code complies with the specification. If it does not comply with the specification, an error will be reported when Maven compiles

Solution: how can this specification be removed? Just execute the following command, which can ignore the PMD check

mvn clean install -Dpmd.skip=true -Dcheckstyle.skip=true

Of course, when Maven compiles, there will be unit test execution, so how to ignore unit test execution?Just execute the following command

mvn clean install -Dmaven.test.skip=true

Therefore, as long as you want to ignore it, you can execute a command directly behind it
in a word:

In order to be compatible with errors, the following methods can be performed:

mvn clean install -Dpmd.skip=true -Dcheckstyle.skip=true -Dmaven.test.skip=true

[Solved] CMake Error at CMakeLists.txt:92 (add_subdirectory)

When compiling GitHub project, you may encounter the following errors:

CMake Error at CMakeLists.txt:92 (add_subdirectory):
 The source directory
xxxxx

CMake Error at src/Runtime/CMakeLists.txt:56 (pybind11_add_module):
 Unknown CMake command "pybind11_add_module".

This is generally a lack of third-party dependencies. You can try the following command:

git submodule init && git submodule update

Reference:
https://stackoverflow.com/questions/59291154/cmake-error-at-cmakelists-txt994-add-subdirectory

How to Solve Redis Cluster Build Error

error 1

WARNING: The TCP backlog setting of 511 cannot be enforced because /proc/sys/net/core/somaxconn is set to the lower value of 128
The length of the largest listening queue of each port does not meet this high-load environment and needs to be adjusted

Solution:echo 2048 > /proc/sys/net/core/somaxconn

error 2

WARNING overcommit_memory is set to 0! Background save may fail under low memory condition
Memory excess warning, setting the current memory to 0 will cause the background save to fail

Solution:
echo "vm.overcommit_memory=1" > /etc/sysctl.conf
#Refresh the configuration file to ensure it takes effect
sysctl vm.overcommit_memory=1

error 3

WARNING you have Transparent Huge Pages (THP) support enabled in your kernel. This will create latency and memory usage issues with Redis
Enabling transparent huge page (THP) support in the kernel will cause Redis delays and memory usage issues

Solution:
echo never > /sys/kernel/mm/transparent_hugepage/enabled

error 4

Error condition on socket for SYNC: Connection reset by peer
The connection was refused because the main server may have bound its own IP address

Solution:

#Modify the master node configuration file
vim /etc/redis/6379.conf 
  bind 0.0.0.0							#Modify the listening address on line 70 to 0.0.0.0

[Solved] Keras Error: KeyError: ‘accuracy‘, KeyError: ‘val_acc‘, KeyError: ‘acc‘

Problem:
keyerror ‘ACC’ is reported when using keras

Reason:
this is a keras version problem. ACC and accuracy are intended to be the same, but different keras versions use different names, so they need to be replaced. val_ So is acc.

Solution:
Print history keyword
Print (history. History. Keys())
change the error part to the printed “K” and “V”“

[Solved] org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot

09:06:12.163 [http-nio-9207-exec-6] ERROR c.s.p.c.GlobalExceptionHandler - [exceptionHandler,90] - 发生其他异常,原因是;{}
org.springframework.http.converter.HttpMessageNotReadableException: JSON parse error: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token; nested exception is com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: java.lang.Object[][0])
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:285)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.read(AbstractJackson2HttpMessageConverter.java:243)
	at org.springframework.web.servlet.mvc.method.annotation.AbstractMessageConverterMethodArgumentResolver.readWithMessageConverters(AbstractMessageConverterMethodArgumentResolver.java:205)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.readWithMessageConverters(RequestResponseBodyMethodProcessor.java:158)
	at org.springframework.web.servlet.mvc.method.annotation.RequestResponseBodyMethodProcessor.resolveArgument(RequestResponseBodyMethodProcessor.java:131)
	at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:121)
	at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:167)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:134)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:105)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:878)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:792)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1040)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006)
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:652)
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:733)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at com.signature.pc.config.HttpServletRequestReplacedFilter.doFilter(HttpServletRequestReplacedFilter.java:35)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.boot.actuate.metrics.web.servlet.WebMvcMetricsFilter.doFilterInternal(WebMvcMetricsFilter.java:93)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201)
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:202)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:97)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:542)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:143)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:78)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:374)
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:888)
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1597)
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: com.fasterxml.jackson.databind.exc.MismatchedInputException: Cannot deserialize instance of `java.lang.String` out of START_OBJECT token
 at [Source: (PushbackInputStream); line: 1, column: 2] (through reference chain: java.lang.Object[][0])
	at com.fasterxml.jackson.databind.exc.MismatchedInputException.from(MismatchedInputException.java:59)
	at com.fasterxml.jackson.databind.DeserializationContext.reportInputMismatch(DeserializationContext.java:1468)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1242)
	at com.fasterxml.jackson.databind.DeserializationContext.handleUnexpectedToken(DeserializationContext.java:1148)
	at com.fasterxml.jackson.databind.deser.std.StdDeserializer._parseString(StdDeserializer.java:615)
	at com.fasterxml.jackson.databind.deser.std.StringArrayDeserializer.deserialize(StringArrayDeserializer.java:157)
	at com.fasterxml.jackson.databind.deser.std.StringArrayDeserializer.deserialize(StringArrayDeserializer.java:21)
	at com.fasterxml.jackson.databind.ObjectMapper._readMapAndClose(ObjectMapper.java:4526)
	at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3521)
	at org.springframework.http.converter.json.AbstractJackson2HttpMessageConverter.readJavaType(AbstractJackson2HttpMessageConverter.java:274)
	... 58 common frames omitted

Interface input parameter format:

Front end parameter transfer format

[{"id":"26a0eac8-edb1-43be-9869-4f7c45c0693a"},
{"id":"E3ECF542585749B996EC0C13907E7D94"}]

.
.
.
the problem is obvious. The format of the value passed by the front end is incorrect. What we need is an array of string type, while the data passed by the front end is object type data.

The front-end transmission parameter is changed to:

[
    "30lkbc2b-1c80-46c3-857e-e934e9842c08",
    "E3ECF542585749B996EC0C13907E7D94"
]

That’s it

[Solved] ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregate

The MySQL table structure is as follows:

mysql> select * from fruits ;
+------+------+------------+---------+
| f_id | s_id | f_name     | f_price |
+------+------+------------+---------+
| a1   |  101 | apple      |    5.20 |
| a2   |  103 | apricot    |    2.20 |
| b1   |  101 | blackberry |   10.20 |
| b2   |  104 | berry      |    7.60 |
| b5   |  107 | xxxx       |    3.60 |
| bs1  |  102 | orange     |   11.20 |
| bs2  |  105 | melon      |    8.20 |
| c0   |  101 | cherry     |    3.20 |
| l2   |  104 | lemon      |    6.40 |
| m1   |  106 | mango      |   15.70 |
| m2   |  105 | xbabay     |    2.60 |
| m3   |  105 | xxtt       |   11.60 |
| o2   |  103 | coconut    |    9.20 |
| t1   |  102 | banana     |   10.30 |
| t2   |  102 | grape      |    5.30 |
| t4   |  107 | xbababa    |    3.60 |
+------+------+------------+---------+

According to s_ ID groups the table data, and the error message is as follows

mysql> select * from fruits group by s_id;
ERROR 1055 (42000): Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
 'exercise.fruits.f_id' which is not functionally dependent on columns in GROUP BY clause; this is incompatible 
 with sql_mode=only_full_group_by

Query SQL_Mode mode

mysql> select @@session.sql_mode;
+-------------------------------------------------------------------------------------------------------------------------------------------+
| @@session.sql_mode                                                                                                                        |
+-------------------------------------------------------------------------------------------------------------------------------------------+
| ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,
ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
+-------------------------------------------------------------------------------------------------------------------------------------------+

Reason: only is added after MySQL 5.7_full_group_By roughly means that the column you select must be included in group by (for example, select a, B from table, group by a, B;), or you are an aggregate column, such as sum(), avg(), max(). The
official website says that SQL mode affects the syntax supported by MySQL and the data verification checks it performs, This makes it easier to use MySQL in different environments and other database servers

Official website reference link: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-setting

Solution:

1. It is found that the set global setting in MySQL does not take effect and cannot be set under my.cnf

sql_mode=STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION

2. Query again is normal

mysql> select * from fruits group by s_id,f_name;
+------+------+------------+---------+
| f_id | s_id | f_name     | f_price |
+------+------+------------+---------+
| a1   |  101 | apple      |    5.20 |
| b1   |  101 | blackberry |   10.20 |
| c0   |  101 | cherry     |    3.20 |
| t1   |  102 | banana     |   10.30 |
| t2   |  102 | grape      |    5.30 |
| bs1  |  102 | orange     |   11.20 |
| a2   |  103 | apricot    |    2.20 |
| o2   |  103 | coconut    |    9.20 |
| b2   |  104 | berry      |    7.60 |
| l2   |  104 | lemon      |    6.40 |
| bs2  |  105 | melon      |    8.20 |
| m2   |  105 | xbabay     |    2.60 |
| m3   |  105 | xxtt       |   11.60 |
| m1   |  106 | mango      |   15.70 |
| t4   |  107 | xbababa    |    3.60 |
| b5   |  107 | xxxx       |    3.60 |
+------+------+------------+---------+

sql_Mode interpretation:

ONLY_FULL_GROUP_BY: For the GROUP BY aggregation operation, if the column in the SELECT is not in the GROUP
Appears in BY, then this SQL is illegal, because the column is not in the GROUP BY clause
 
NO_AUTO_VALUE_ON_ZERO: This value affects the insertion of self-growing columns. By default, inserting 0 or NULL means that the next self-increasing value is generated. If the user
Hope that the inserted value is 0, and the column is self-increasing, then this option is useful.
 
STRICT_TRANS_TABLES: In this mode, if a value cannot be inserted into a transaction table, the current operation is interrupted, and there is no restriction on non-transactional tables
NO_ZERO_IN_DATE: In strict mode, the date and month are not allowed to be zero
 
NO_ZERO_DATE: Set this value. The mysql database does not allow the insertion of a zero date. Inserting a zero date will throw an error instead of a warning.
 
ERROR_FOR_DIVISION_BY_ZERO: During INSERT or UPDATE, if the data is divided by zero, an error is generated instead of a warning. like
If the mode is not given, then MySQL returns NULL when the data is divided by zero
 
NO_AUTO_CREATE_USER: prohibit GRANT from creating users with empty passwords
 
NO_ENGINE_SUBSTITUTION:
If the required storage engine is disabled or not compiled, then an error is thrown. When this value is not set, replace with the default storage engine and throw an exception
 
PIPES_AS_CONCAT:
Treat "||" as a string concatenation operator instead of an OR operator, which is the same as the Oracle database and similar to the string concatenation function Concat
 
ANSI_QUOTES: When ANSI_QUOTES is enabled, double quotes cannot be used to quote a string because it is interpreted as an identifier

ERROR: configuration failed for package ‘openssl’ [How to Solve]

ERROR: configuration failed for package ‘openssl’
removing ‘/usr/local/lib/R/site-library/openssl’
The ubuntu system lacks openssl:

apt-get install openssl
apt-get install openssl-devel

Or:

wget https://www.openssl.org/source/openssl-1.1.1i.tar.gz

tar -xvf  openssl-1.1.1i.tar.gz

cd openssl-1.1.1i/

./config 

make && make install

./config shared 

make clean

make  && make install

Node rsa Library Error [InvalidAsn1Error]: Expected 0x2: got 0x30

Node RSA library, read the key file, add and remove the secret report error

throw newInvalidAsn1Error(‘Expected 0x’ + tag.toString(16) +
^

Error [InvalidAsn1Error]: Expected 0x2: got 0x30

The reason is the key file format problem

Pkcs1: public key (- — begin RSA public key ——) and private key (- — begin RSA private key ——) pkcs8: public key (- — begin RSA public key ——) and private key (- — begin private key—

To put it simply, delete the word RSA in the public key and private key

The node RSA library is formatted in this way.

[Solved] BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans‘

Created a SpringBoot project, used SpringCloud, and then started the project and reported an error:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‘configurationPropertiesBeans’ defined in class path resource [org/springframework/cloud/autoconfigure/ConfigurationPropertiesRebinderAutoConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.cloud.context.properties.ConfigurationPropertiesBeans]: Factory method ‘configurationPropertiesBeans’ threw exception; nested exception is java.lang.NoClassDefFoundError: org/springframework/boot/context/properties/ConfigurationBeanFactoryMetadata


It is found that the version of SpringBoot is inconsistent with the version of SpringCloud
Corresponding to the modified version


   <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.6.RELEASE</version>
        <relativePath/>
    </parent>
             <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version></version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>